Skip to content

D[0] docs(config): Example 3 - custom vendor chunks using RegEx #2518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/content/plugins/split-chunks-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ contributors:
- EugeneHlushko
- byzyk
- madhavarshney
- sakhisheikh
related:
- title: webpack's automatic deduplication algorithm example
url: https://github.com/webpack/webpack/blob/master/examples/many-pages/README.md
Expand Down Expand Up @@ -344,3 +345,28 @@ module.exports = {
```

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.

### Split Chunks: Example 3

Create a `custom vendor` chunk, which contains certain `node_modules` packages matched by `RegExp`.

__webpack.config.js__

```js
module.exports = {
//...
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
name: 'vendor',
chunks: 'all',
}
}
}
}
};
```

T> This will result in splitting `react` and `react-dom` into a separate chunk. If you're not sure what packages have been included in a chunk you may refer to [Bundle Analysis](/guides/code-splitting/#bundle-analysis) section for details.