Skip to content

Commit c81e77e

Browse files
author
sakhisheikh
committed
docs(config): Example 3 - custom vendor chunk using RegEx
1 parent 649ae3a commit c81e77e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/content/plugins/split-chunks-plugin.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ contributors:
88
- EugeneHlushko
99
- byzyk
1010
- madhavarshney
11+
- sakhisheikh
1112
related:
1213
- title: webpack's automatic deduplication algorithm example
1314
url: https://github.com/webpack/webpack/blob/master/examples/many-pages/README.md
@@ -344,3 +345,27 @@ module.exports = {
344345
```
345346

346347
W> This might result in a large chunk containing all external packages. It is recommended to only include your core frameworks and utilities and dynamically load the rest of the dependencies.
348+
349+
### Split Chunks: Example 3
350+
351+
Create a `custom vendors` chunk, which includes only those `node_modules` from the whole application which passes the RegEx Test
352+
353+
__webpack.config.js__
354+
355+
```js
356+
module.exports = {
357+
//...
358+
optimization: {
359+
splitChunks: {
360+
cacheGroups: {
361+
vendor: {
362+
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
363+
name: 'vendor',
364+
chunks: 'all',
365+
}
366+
}
367+
}
368+
}
369+
};
370+
```
371+
T> This will result into a vendor chunk containing desired libraries provided in RegEx patter. A better understanding of chunks can be visualized by [webpack-visualizer](https://chrisbateman.github.io/webpack-visualizer/).

0 commit comments

Comments
 (0)