@@ -398,6 +398,8 @@ module.exports = {
398398> Don't use Webpack's ` output.filename ` , hold all relevant settings in one place - in plugin options.\
399399> Both places have the same effect, but ` js.filename ` has priority over ` output.filename ` .
400400
401+ For ` splitChunks ` see [ How to configure splitChunks] ( #recipe-split-chunks ) .
402+
401403No additional template loader is required. The plugin handles templates with base ` EJS ` -like syntax automatically.
402404The default templating engine is [ Eta] ( https://eta.js.org ) .
403405
@@ -537,7 +539,7 @@ See [boilerplate](https://github.com/webdiscus/webpack-html-scss-boilerplate)
537539 - [ How to process a PHP template] ( #recipe-preprocessor-php )
538540 - [ How to pass data into multiple templates] ( #recipe-pass-data-to-templates )
539541 - [ How to use some different template engines] ( #recipe-diff-templates )
540- - [ How to config ` splitChunks ` ] ( #recipe-split-chunks )
542+ - [ How to configure ` splitChunks ` ] ( #recipe-split-chunks )
541543 - [ How to keep package name for ** split chunks** from ** node_modules** ] ( #recipe-split-chunks-keep-module-name )
542544 - [ How to split CSS files] ( #recipe-split-css )
5435452 . [ Problems & Solutions] ( #solutions )
@@ -6251,20 +6253,21 @@ module.exports = {
62516253
62526254<a id="recipe-split-chunks" name="recipe-split-chunks"></a>
62536255
6254- ### How to config ` splitChunks`
6256+ ### How to configure ` splitChunks`
62556257
62566258Webpack tries to split every entry file, include template files, which completely breaks the compilation process in the plugin.
62576259
62586260To avoid this issue, you must specify which scripts should be split, using ` optimization .splitChunks .cacheGroups ` :
62596261
6260- ` ` ` js
6262+ ` ` ` diff
62616263module .exports = {
62626264 optimization: {
62636265 splitChunks: {
6266+ - chunks: ' all' , // <= DO NOT use this here
62646267 cacheGroups: {
62656268 scripts: {
62666269 test: / \. (js| ts)$ / , // <= IMPORTANT: split only script files
6267- chunks: ' all' ,
6270+ + chunks: ' all' , // <= DEFINE it here only
62686271 },
62696272 },
62706273 },
@@ -6276,6 +6279,17 @@ module.exports = {
62766279>
62776280> In the ` test` option must be specified all extensions of scripts which should be split.
62786281
6282+ > ⚠️ **Warning**
6283+ >
6284+ > DO NOT use the ` chunks: ' all' ` option globally!
6285+ >
6286+ > The ` splitChunks .chunks : ' all' ` option splits all types of chunks, but it make no sense, because we need split only scripts.
6287+ > Templates, CSS, images and other assets can't be split.
6288+ >
6289+ > Define ` chunks: ' all' ` only in a cache group where is specified the ` test` option for your scripts.
6290+ >
6291+ > ‼️ The ` splitChunks .chunks ` option will be automatically removed, because some assets can't be resolved or output files may be corrupted!
6292+
62796293See details by [splitChunks.cacheGroups](https://webpack.js.org/plugins/split-chunks-plugin/#splitchunkscachegroups).
62806294
62816295For example, in a template are used the scripts and styles from ` node_modules` :
@@ -6299,7 +6313,7 @@ For example, in a template are used the scripts and styles from `node_modules`:
62996313> In the generated HTML, all script tags remain in their original places, and the split chunks will be added there
63006314> in the order in which Webpack generated them.
63016315
6302- In this use case the ` optimization .cacheGroups .{cacheGroup}.test ` option must match exactly only JS files from ` node_modules` :
6316+ In this use case the ` optimization .splitChunks . cacheGroups .{cacheGroup}.test ` option must match exactly only JS files from ` node_modules` :
63036317
63046318` ` ` js
63056319module .exports = {
@@ -6309,8 +6323,7 @@ module.exports = {
63096323 cacheGroups: {
63106324 vendor: {
63116325 test: / [\\ /] node_modules[\\ /] . + \. (js| ts)$ / , // <= IMPORTANT: split only script files
6312- name: ' vendor' ,
6313- chunks: ' all' ,
6326+ chunks: ' all' , // <= DEFINE it here only
63146327 },
63156328 },
63166329 },
@@ -6332,7 +6345,7 @@ module.exports = {
63326345
63336346### How to keep package name for split chunks from node_modules
63346347
6335- To save split chunks under a custom name use ` optimization .cacheGroups .{cacheGroup}.name ` as function.
6348+ To save split chunks under a custom name use ` optimization .splitChunks . cacheGroups .{cacheGroup}.name ` as function.
63366349
63376350For example, many node modules are imported in the ` main .js ` :
63386351
@@ -6376,12 +6389,11 @@ module.exports = {
63766389 optimization: {
63776390 runtimeChunk: true ,
63786391 splitChunks: {
6379- // chunks: 'all', // DO NOT use it here, otherwise the compiled pages will be corrupted
63806392 maxSize: 1000000 , // split chunks bigger than 100KB, defaults is 20KB
63816393 cacheGroups: {
63826394 app: {
63836395 test: / \. (js| ts)$ / , // <= IMPORTANT: split only script files
6384- chunks: ' all' , // <= use it only in cache groups
6396+ chunks: ' all' , // <= define it only in a cache group
63856397 name ({ context }, chunks , groupName ) {
63866398 // save split chunks of the node module under package name
63876399 if (/ [\\ /] node_modules[\\ /] / .test (context)) {
0 commit comments