You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/configuration/cache.mdx
+25-4Lines changed: 25 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,22 @@ sort: 12
4
4
contributors:
5
5
- snitin315
6
6
- chenxsan
7
+
- shivxmsharma
7
8
---
8
9
9
10
## cache
10
11
11
12
`boolean``object`
12
13
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`|
14
23
15
24
**webpack.config.js**
16
25
@@ -28,7 +37,15 @@ While setting `cache.type` to `'filesystem'` opens up more options for configura
28
37
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.
29
38
30
39
- 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
+
32
49
- <Badgetext="5.35.0+" />
33
50
34
51
**webpack.config.js**
@@ -316,9 +333,13 @@ Define the lifespan of unused cache entries in the memory cache.
316
333
317
334
- `cache.maxMemoryGenerations`: small numbers > 0 will have a performance cost for the GC operation. It gets lower as the number increases.
318
335
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/):
320
337
321
-
`cache.maxMemoryGenerations` option is only available when [`cache.type`](#cachetype) is set to `'filesystem'`.
@@ -26,7 +27,15 @@ Webpack runs optimizations for you depending on the chosen [`mode`](/configurati
26
27
27
28
`boolean`
28
29
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`|
30
39
31
40
**webpack.config.js**
32
41
@@ -58,8 +67,8 @@ The default value of `optimization.chunkIds` depends on the [`mode`](/configurat
58
67
59
68
| Mode | Default |
60
69
| ------------- | ----------------- |
61
-
|`development`|`'named'`|
62
70
|`production`|`'deterministic'`|
71
+
|`development`|`'named'`|
63
72
|`none`|`'natural'`|
64
73
65
74
The following string values are supported:
@@ -106,7 +115,14 @@ export default {
106
115
`boolean`
107
116
108
117
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`|
110
126
111
127
**webpack.config.js**
112
128
@@ -121,10 +137,18 @@ export default {
121
137
122
138
## optimization.emitOnErrors
123
139
124
-
`boolean = false`
140
+
`boolean`
125
141
126
142
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.
127
143
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
+
128
152
**webpack.config.js**
129
153
130
154
```js
@@ -140,17 +164,23 @@ W> If you are using webpack [CLI](/api/cli/), the webpack process will not exit
140
164
141
165
## optimization.avoidEntryIife
142
166
143
-
`boolean = false`
167
+
`boolean`
144
168
145
169
<Badgetext="5.95.0+" />
146
170
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 ...
148
172
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`...
150
174
151
175
Currently, `optimization.avoidEntryIife` can only optimize a single entry module along with other modules.
152
176
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`|
154
184
155
185
**webpack.config.js**
156
186
@@ -169,7 +199,15 @@ W> The `optimization.avoidEntryIife` option can negatively affect build performa
169
199
170
200
`boolean`
171
201
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`|
173
211
174
212
**webpack.config.js**
175
213
@@ -184,10 +222,18 @@ export default {
184
222
185
223
## optimization.innerGraph
186
224
187
-
`boolean = true`
225
+
`boolean`
188
226
189
227
`optimization.innerGraph` tells webpack whether to conduct inner graph analysis for unused exports.
190
228
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
+
191
237
**webpack.config.js**
192
238
193
239
```js
@@ -205,7 +251,13 @@ export default {
205
251
206
252
`optimization.mangleExports` allows to control export mangling.
207
253
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`|
209
261
210
262
The following values are supported:
211
263
@@ -263,10 +315,18 @@ export default {
263
315
264
316
## optimization.minimize
265
317
266
-
`boolean = true`
318
+
`boolean`
267
319
268
320
Tell webpack to minimize the bundle using the [TerserPlugin](/plugins/terser-webpack-plugin/) or the plugin(s) specified in [`optimization.minimizer`](#optimizationminimizer).
269
321
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
+
270
330
**webpack.config.js**
271
331
272
332
```js
@@ -413,9 +473,17 @@ W> `moduleIds: total-size` has been removed in webpack 5.
413
473
414
474
## optimization.nodeEnv
415
475
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`.
417
479
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`|
419
487
420
488
Possible values:
421
489
@@ -475,7 +543,15 @@ export default {
475
543
476
544
`boolean`
477
545
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`|
479
555
480
556
**webpack.config.js**
481
557
@@ -579,7 +655,7 @@ export default {
579
655
580
656
## optimization.sideEffects
581
657
582
-
`boolean = true``string: 'flag'`
658
+
`boolean``string: 'flag'`
583
659
584
660
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.
585
661
@@ -597,6 +673,14 @@ T> Please note that `sideEffects` should be in the npm module's `package.json` f
597
673
598
674
`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.
599
675
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
+
600
684
**webpack.config.js**
601
685
602
686
```js
@@ -619,8 +703,6 @@ export default {
619
703
};
620
704
```
621
705
622
-
The `'flag'` value is used by default in non-production builds.
623
-
624
706
T> `optimization.sideEffects` will also flag modules as side effect free when they contain only side effect free statements.
625
707
626
708
## optimization.splitChunks
@@ -631,11 +713,19 @@ By default webpack v4+ provides new common chunks strategies out of the box for
631
713
632
714
## optimization.usedExports
633
715
634
-
`boolean = true``string: 'global'`
716
+
`boolean``string: 'global'`
635
717
636
718
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.
637
719
Dead code elimination in minimizers will benefit from this and can remove unused exports.
638
720
721
+
The default value of `optimization.usedExports` depends on the [`mode`](/configuration/mode/):
Copy file name to clipboardExpand all lines: src/content/configuration/output.mdx
+11-2Lines changed: 11 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,7 @@ contributors:
31
31
- long76
32
32
- ahabhgk
33
33
- tanyabouman
34
+
- shivxmsharma
34
35
---
35
36
36
37
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
2172
2173
2173
2174
## output.pathinfo
2174
2175
2175
-
`boolean=true``string:'verbose'`
2176
+
`boolean``string:'verbose'`
2176
2177
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` |
2178
2187
2179
2188
W> While the data these comments can provide is useful during development when reading the generated code, it **should not** be used in production.
0 commit comments