Skip to content

Commit ab35060

Browse files
committed
docs: use defaults table for mode-specific configuration options
Closes #6356
1 parent e24d484 commit ab35060

File tree

7 files changed

+206
-28
lines changed

7 files changed

+206
-28
lines changed

src/content/configuration/cache.mdx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ sort: 12
44
contributors:
55
- snitin315
66
- chenxsan
7+
- shivxmsharma
78
---
89

910
## cache
1011

1112
`boolean` `object`
1213

13-
Cache the generated webpack modules and chunks to improve build speed. `cache` is set to `type: 'memory'` in [`development` mode](/configuration/mode/#mode-development) and disabled in [`production` mode](/configuration/mode/#mode-production). `cache: true` is an alias to `cache: { type: 'memory' }`. To disable caching pass `false`:
14+
Cache the generated webpack modules and chunks to improve build speed. `cache: true` is an alias to `cache: { type: 'memory' }`. To disable caching pass `false`:
15+
16+
The default value of `cache` depends on the [`mode`](/configuration/mode/):
17+
18+
| Mode | Default |
19+
| ------------- | -------------------- |
20+
| `production` | `false` |
21+
| `development` | `{ type: 'memory' }` |
22+
| `none` | `false` |
1423

1524
**webpack.config.js**
1625

@@ -28,7 +37,15 @@ While setting `cache.type` to `'filesystem'` opens up more options for configura
2837
Collect unused memory allocated during deserialization, only available when [`cache.type`](#cachetype) is set to `'filesystem'`. This requires copying data into smaller buffers and has a performance cost.
2938

3039
- Type: `boolean`
31-
- It defaults to `false` in production mode and `true` in development mode.
40+
41+
The default value of `cache.allowCollectingMemory` depends on the [`mode`](/configuration/mode/):
42+
43+
| Mode | Default |
44+
| ------------- | ------- |
45+
| `production` | `false` |
46+
| `development` | `true` |
47+
| `none` | `false` |
48+
3249
- <Badge text="5.35.0+" />
3350

3451
**webpack.config.js**
@@ -316,9 +333,13 @@ Define the lifespan of unused cache entries in the memory cache.
316333
317334
- `cache.maxMemoryGenerations`: small numbers > 0 will have a performance cost for the GC operation. It gets lower as the number increases.
318335
319-
- `cache.maxMemoryGenerations`: defaults to 10 in `development` mode and to `Infinity` in `production` mode.
336+
The default value of `cache.maxMemoryGenerations` depends on the [`mode`](/configuration/mode/):
320337
321-
`cache.maxMemoryGenerations` option is only available when [`cache.type`](#cachetype) is set to `'filesystem'`.
338+
| Mode | Default |
339+
| ------------- | ---------- |
340+
| `production` | `Infinity` |
341+
| `development` | `10` |
342+
| `none` | `Infinity` |
322343
323344
**webpack.config.js**
324345

src/content/configuration/module.mdx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ contributors:
2424
- vabushkevich
2525
- ahabhgk
2626
- hai-x
27+
- shivxmsharma
2728
---
2829

2930
These options determine how the [different types of modules](/concepts/modules) within a project will be treated.
@@ -984,7 +985,15 @@ export default {
984985
985986
### module.parser.json.exportsDepth
986987
987-
The depth of json dependency flagged as `exportInfo`. By default, it is set to `Infinity` in production mode, and `1` in development mode.
988+
The depth of json dependency flagged as `exportInfo`.
989+
990+
The default value of `module.parser.json.exportsDepth` depends on the [`mode`](/configuration/mode/):
991+
992+
| Mode | Default |
993+
| ------------- | ---------- |
994+
| `production` | `Infinity` |
995+
| `development` | `1` |
996+
| `none` | `1` |
988997
989998
- Type: `number`
990999
- Available: <Badge text='5.98.0+' />

src/content/configuration/optimization.mdx

Lines changed: 109 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ contributors:
1515
- chenxsan
1616
- Roberto14
1717
- hai-x
18+
- shivxmsharma
1819
related:
1920
- title: "webpack 4: Code Splitting, chunk graph and the splitChunks optimization"
2021
url: https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
@@ -26,7 +27,15 @@ Webpack runs optimizations for you depending on the chosen [`mode`](/configurati
2627

2728
`boolean`
2829

29-
Tells webpack to check the incompatible types of WebAssembly modules when they are imported/exported. By default `optimization.checkWasmTypes` is enabled in `production` [mode](/configuration/mode/) and disabled elsewise.
30+
Tells webpack to check the incompatible types of WebAssembly modules when they are imported/exported.
31+
32+
The default value of `optimization.checkWasmTypes` depends on the [`mode`](/configuration/mode/):
33+
34+
| Mode | Default |
35+
| ------------- | ------- |
36+
| `production` | `true` |
37+
| `development` | `false` |
38+
| `none` | `false` |
3039

3140
**webpack.config.js**
3241

@@ -58,8 +67,8 @@ The default value of `optimization.chunkIds` depends on the [`mode`](/configurat
5867

5968
| Mode | Default |
6069
| ------------- | ----------------- |
61-
| `development` | `'named'` |
6270
| `production` | `'deterministic'` |
71+
| `development` | `'named'` |
6372
| `none` | `'natural'` |
6473

6574
The following string values are supported:
@@ -106,7 +115,14 @@ export default {
106115
`boolean`
107116

108117
Tells webpack to find segments of the module graph which can be safely concatenated into a single module. Depends on [`optimization.providedExports`](#optimizationprovidedexports) and [`optimization.usedExports`](#optimizationusedexports).
109-
By default `optimization.concatenateModules` is enabled in `production` [mode](/configuration/mode/) and disabled elsewise.
118+
119+
The default value of `optimization.concatenateModules` depends on the [`mode`](/configuration/mode/):
120+
121+
| Mode | Default |
122+
| ------------- | ------- |
123+
| `production` | `true` |
124+
| `development` | `false` |
125+
| `none` | `false` |
110126

111127
**webpack.config.js**
112128

@@ -121,10 +137,18 @@ export default {
121137

122138
## optimization.emitOnErrors
123139

124-
`boolean = false`
140+
`boolean`
125141

126142
Use the `optimization.emitOnErrors` to emit assets whenever there are errors while compiling. This ensures that erroring assets are emitted. Critical errors are emitted into the generated code and will cause errors at runtime.
127143

144+
The default value of `optimization.emitOnErrors` depends on the [`mode`](/configuration/mode/):
145+
146+
| Mode | Default |
147+
| ------------- | ------- |
148+
| `production` | `false` |
149+
| `development` | `true` |
150+
| `none` | `true` |
151+
128152
**webpack.config.js**
129153

130154
```js
@@ -140,17 +164,23 @@ W> If you are using webpack [CLI](/api/cli/), the webpack process will not exit
140164

141165
## optimization.avoidEntryIife
142166

143-
`boolean = false`
167+
`boolean`
144168

145169
<Badge text="5.95.0+" />
146170

147-
T> IIFE (Immediately Invoked Function Expression) is a function that runs immediately after it is created. Webpack uses it to wrap code and avoid variable conflicts.
171+
T> IIFE ...
148172

149-
Use `optimization.avoidEntryIife` to avoid wrapping the entry module in an IIFE when it is required (search for `"This entry needs to be wrapped in an IIFE because"` in [JavascriptModulesPlugin](https://github.com/webpack/webpack/blob/main/lib/javascript/JavascriptModulesPlugin.js)). This approach helps optimize performance for JavaScript engines and enables tree shaking when building ESM libraries.
173+
Use `optimization.avoidEntryIife` ...
150174

151175
Currently, `optimization.avoidEntryIife` can only optimize a single entry module along with other modules.
152176

153-
By default, `optimization.avoidEntryIife` is enabled in `production` [mode](/configuration/mode/) and disabled otherwise.
177+
The default value of `optimization.avoidEntryIife` depends on the [`mode`](/configuration/mode/):
178+
179+
| Mode | Default |
180+
| ------------- | ------- |
181+
| `production` | `true` |
182+
| `development` | `false` |
183+
| `none` | `false` |
154184

155185
**webpack.config.js**
156186

@@ -169,7 +199,15 @@ W> The `optimization.avoidEntryIife` option can negatively affect build performa
169199

170200
`boolean`
171201

172-
Tells webpack to determine and flag chunks which are subsets of other chunks in a way that subsets don’t have to be loaded when the bigger chunk has been already loaded. By default `optimization.flagIncludedChunks` is enabled in `production` [mode](/configuration/mode/) and disabled elsewise.
202+
Tells webpack to determine and flag chunks which are subsets of other chunks in a way that subsets don't have to be loaded when the bigger chunk has been already loaded.
203+
204+
The default value of `optimization.flagIncludedChunks` depends on the [`mode`](/configuration/mode/):
205+
206+
| Mode | Default |
207+
| ------------- | ------- |
208+
| `production` | `true` |
209+
| `development` | `false` |
210+
| `none` | `false` |
173211

174212
**webpack.config.js**
175213

@@ -184,10 +222,18 @@ export default {
184222

185223
## optimization.innerGraph
186224

187-
`boolean = true`
225+
`boolean`
188226

189227
`optimization.innerGraph` tells webpack whether to conduct inner graph analysis for unused exports.
190228

229+
The default value of `optimization.innerGraph` depends on the [`mode`](/configuration/mode/):
230+
231+
| Mode | Default |
232+
| ------------- | ------- |
233+
| `production` | `true` |
234+
| `development` | `false` |
235+
| `none` | `false` |
236+
191237
**webpack.config.js**
192238

193239
```js
@@ -205,7 +251,13 @@ export default {
205251

206252
`optimization.mangleExports` allows to control export mangling.
207253

208-
By default `optimization.mangleExports: 'deterministic'` is enabled in `production` [mode](/configuration/mode/) and disabled elsewise.
254+
The default value of `optimization.mangleExports` depends on the [`mode`](/configuration/mode/):
255+
256+
| Mode | Default |
257+
| ------------- | ------- |
258+
| `production` | `true` |
259+
| `development` | `false` |
260+
| `none` | `false` |
209261

210262
The following values are supported:
211263

@@ -263,10 +315,18 @@ export default {
263315

264316
## optimization.minimize
265317

266-
`boolean = true`
318+
`boolean`
267319

268320
Tell webpack to minimize the bundle using the [TerserPlugin](/plugins/terser-webpack-plugin/) or the plugin(s) specified in [`optimization.minimizer`](#optimizationminimizer).
269321

322+
The default value of `optimization.minimize` depends on the [`mode`](/configuration/mode/):
323+
324+
| Mode | Default |
325+
| ------------- | ------- |
326+
| `production` | `true` |
327+
| `development` | `false` |
328+
| `none` | `false` |
329+
270330
**webpack.config.js**
271331

272332
```js
@@ -413,9 +473,17 @@ W> `moduleIds: total-size` has been removed in webpack 5.
413473

414474
## optimization.nodeEnv
415475

416-
`boolean = false` `string`
476+
`boolean: false` `string`
477+
478+
Tells webpack to set `process.env.NODE_ENV` to a given string value. `optimization.nodeEnv` uses [DefinePlugin](/plugins/define-plugin/) unless set to `false`.
417479

418-
Tells webpack to set `process.env.NODE_ENV` to a given string value. `optimization.nodeEnv` uses [DefinePlugin](/plugins/define-plugin/) unless set to `false`. `optimization.nodeEnv` **defaults** to [mode](/configuration/mode/) if set, else falls back to `'production'`.
480+
The default value of `optimization.nodeEnv` depends on the [`mode`](/configuration/mode/):
481+
482+
| Mode | Default |
483+
| ------------- | --------------- |
484+
| `production` | `'production'` |
485+
| `development` | `'development'` |
486+
| `none` | `false` |
419487

420488
Possible values:
421489

@@ -475,7 +543,15 @@ export default {
475543

476544
`boolean`
477545

478-
Adds an additional hash compilation pass after the assets have been processed to get the correct asset content hashes. If `realContentHash` is set to `false`, internal data is used to calculate the hash and it can change when assets are identical. By default `optimization.realContentHash` is enabled in production [mode](/configuration/mode/) and disabled otherwise.
546+
Adds an additional hash compilation pass after the assets have been processed to get the correct asset content hashes. If `realContentHash` is set to `false`, internal data is used to calculate the hash and it can change when assets are identical.
547+
548+
The default value of `optimization.realContentHash` depends on the [`mode`](/configuration/mode/):
549+
550+
| Mode | Default |
551+
| ------------- | ------- |
552+
| `production` | `true` |
553+
| `development` | `false` |
554+
| `none` | `false` |
479555

480556
**webpack.config.js**
481557

@@ -579,7 +655,7 @@ export default {
579655

580656
## optimization.sideEffects
581657

582-
`boolean = true` `string: 'flag'`
658+
`boolean` `string: 'flag'`
583659

584660
Tells webpack to recognise the [`sideEffects`](https://github.com/webpack/webpack/blob/main/examples/side-effects/README.md) flag in `package.json` or rules to skip over modules which are flagged to contain no side effects when exports are not used.
585661

@@ -597,6 +673,14 @@ T> Please note that `sideEffects` should be in the npm module's `package.json` f
597673

598674
`optimization.sideEffects` depends on [`optimization.providedExports`](#optimizationprovidedexports) to be enabled. This dependency has a build time cost, but eliminating modules has positive impact on performance because of less code generation. Effect of this optimization depends on your codebase, try it for possible performance wins.
599675

676+
The default value of `optimization.sideEffects` depends on the [`mode`](/configuration/mode/):
677+
678+
| Mode | Default |
679+
| ------------- | -------- |
680+
| `production` | `true` |
681+
| `development` | `'flag'` |
682+
| `none` | `'flag'` |
683+
600684
**webpack.config.js**
601685

602686
```js
@@ -619,8 +703,6 @@ export default {
619703
};
620704
```
621705

622-
The `'flag'` value is used by default in non-production builds.
623-
624706
T> `optimization.sideEffects` will also flag modules as side effect free when they contain only side effect free statements.
625707

626708
## optimization.splitChunks
@@ -631,11 +713,19 @@ By default webpack v4+ provides new common chunks strategies out of the box for
631713

632714
## optimization.usedExports
633715

634-
`boolean = true` `string: 'global'`
716+
`boolean` `string: 'global'`
635717

636718
Tells webpack to determine used exports for each module. This depends on [`optimization.providedExports`](#optimizationprovidedexports). Information collected by `optimization.usedExports` is used by other optimizations or code generation i.e. exports are not generated for unused exports, export names are mangled to single char identifiers when all usages are compatible.
637719
Dead code elimination in minimizers will benefit from this and can remove unused exports.
638720

721+
The default value of `optimization.usedExports` depends on the [`mode`](/configuration/mode/):
722+
723+
| Mode | Default |
724+
| ------------- | ------- |
725+
| `production` | `true` |
726+
| `development` | `false` |
727+
| `none` | `false` |
728+
639729
**webpack.config.js**
640730

641731
```js

src/content/configuration/output.mdx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ contributors:
3131
- long76
3232
- ahabhgk
3333
- tanyabouman
34+
- shivxmsharma
3435
---
3536

3637
The top-level `output` key contains a set of options instructing webpack on how and where it should output your bundles, assets, and anything else you bundle or load with webpack.
@@ -2172,9 +2173,17 @@ W> The path must not contain an exclamation mark (`!`) as it is reserved by webp
21722173
21732174
## output.pathinfo
21742175
2175-
`boolean=true` `string: 'verbose'`
2176+
`boolean` `string: 'verbose'`
21762177
2177-
Tells webpack to include comments in bundles with information about the contained modules. This option defaults to `true` in `development` and `false` in `production` [mode](/configuration/mode/) respectively. `'verbose'` shows more information like exports, runtime requirements and bailouts.
2178+
Tells webpack to include comments in bundles with information about the contained modules. `'verbose'` shows more information like exports, runtime requirements and bailouts.
2179+
2180+
The default value of `output.pathinfo` depends on the [`mode`](/configuration/mode/):
2181+
2182+
| Mode | Default |
2183+
| ------------- | ------- |
2184+
| `production` | `false` |
2185+
| `development` | `true` |
2186+
| `none` | `false` |
21782187
21792188
W> While the data these comments can provide is useful during development when reading the generated code, it **should not** be used in production.
21802189

src/content/configuration/performance.mdx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ contributors:
77
- byzyk
88
- madhavarshney
99
- EugeneHlushko
10+
- shivxmsharma
1011
---
1112

1213
These options allows you to control how webpack notifies you of assets and entry points that exceed a specific file limit.
@@ -47,10 +48,18 @@ The example above will only give you performance hints based on `.js` files.
4748

4849
### performance.hints
4950

50-
`string = 'warning': 'error' | 'warning'` `boolean: false`
51+
`string: 'error' | 'warning'` `boolean: false`
5152

5253
Turns hints on/off. In addition, tells webpack to throw either an error or a warning when hints are found.
5354

55+
The default value of `performance.hints` depends on the [`mode`](/configuration/mode/):
56+
57+
| Mode | Default |
58+
| ------------- | ----------- |
59+
| `production` | `'warning'` |
60+
| `development` | `false` |
61+
| `none` | `false` |
62+
5463
Given an asset is created that is over 250kb:
5564

5665
```js

0 commit comments

Comments
 (0)