webpack/examples/many-pages/template.md

36 lines
1.9 KiB
Markdown
Raw Permalink Normal View History

2018-05-18 02:33:18 +08:00
# Info
2018-07-10 04:48:12 +08:00
This example illustrates webpack's algorithm for automatic deduplication using `optimization.splitChunks`.
2018-05-18 02:33:18 +08:00
This example application contains 7 pages, each importing 1-3 modules from the `node_modules` folder (vendor libs) and 0-3 modules from the `stuff` folder (application modules). In reality, an application is probably more complex, but the same mechanisms apply.
2018-05-18 02:33:18 +08:00
The following configuration is used:
- `optimization.splitChunks.chunks: "all"` - This opt-in into automatic splitting of initial chunks which is off by default
- `optimization.splitChunks.maxInitial/AsyncRequests: 20` - This opt-in into an HTTP2 optimized splitting mode by increasing the allowed amount of requests. The browser only supports 6 requests in parallel for HTTP1.1.
2018-05-18 02:33:18 +08:00
# Interpreting the result
- `pageA.js` the normal output files for the entrypoint `pageA`
- `vendors~pageD~pageE~pageF~pageG.js` vendor libs shared by these pages extracted into a separate output file when larger than the threshold in size
- `vendors~pageA.js` vendors only used by a single page but larger than the threshold in size
- `pageA~pageD~pageF.js` application modules shared by these pages and larger than the threshold in size
2018-05-18 02:33:18 +08:00
Here, the threshold is 40 bytes but by default (in a real application) 30kb.
2018-05-18 02:33:18 +08:00
2020-03-13 00:51:26 +08:00
Some modules are intentionally duplicated, i. e. `./stuff/s4.js` is shared by `pageA` and `pageC`, but it's the only shared module so no separate output file is created because it would be smaller than the threshold. A separate request (which comes with an overhead and worsen gzipping) is not worth the extra bytes.
2018-05-18 02:33:18 +08:00
Note: decreasing `maxInitial/AsyncRequest` will increase duplication further to reduce the number of requests. Duplication doesn't affect the initial page load, it only affects download size of navigations to other pages of the application.
2018-05-18 02:33:18 +08:00
## webpack.config.js
```
_{{webpack.config.js}}_
2018-05-18 02:33:18 +08:00
```
## Production mode
```
_{{production:stdout}}_
```