Skip to content

Commit 2ca5e8d

Browse files
committed
docs(optimization): add optimization.avoidEntryIife
1 parent 60a7ca9 commit 2ca5e8d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/content/configuration/optimization.mdx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,29 @@ module.exports = {
124124

125125
W> If you are using webpack [CLI](/api/cli/), the webpack process will not exit with an error code while this plugin is enabled. If you want webpack to "fail" when using the CLI, please check out the [`bail` option](/api/cli/#advanced-options).
126126

127+
## optimization.entryIife
128+
129+
`boolean = false`
130+
131+
Use `optimization.entryIife` to avoid wrapping the entry module in an IIFE when it is required (search for `"This entry need 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.
132+
133+
Currently, `optimization.entryIife` can only optimize a single entry module along with other modules.
134+
135+
By default `optimization.entryIife` is enabled in `production` [mode](/configuration/mode/) and disabled elsewise.
136+
137+
**webpack.config.js**
138+
139+
```js
140+
module.exports = {
141+
//...
142+
optimization: {
143+
entryIife: true,
144+
},
145+
};
146+
```
147+
148+
W> The `⁠optimization.entryIife` option can negatively affect build performance, if you prioritize build performance over these optimizations, consider disabling this option.
149+
127150
## optimization.flagIncludedChunks
128151

129152
`boolean`
@@ -425,7 +448,7 @@ module.exports = {
425448

426449
`boolean`
427450

428-
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 and disabled elsewise.
451+
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 elsewise.
429452

430453
**webpack.config.js**
431454

0 commit comments

Comments
 (0)