Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created September 11, 2019 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasvirkus/52e8df310634207c46d937c2606a467b to your computer and use it in GitHub Desktop.
Save andreasvirkus/52e8df310634207c46d937c2606a467b to your computer and use it in GitHub Desktop.
// See an excellent explanation over at
// https://medium.com/hackernoon/the-100-correct-way-to-split-your-chunks-with-webpack-f8a9df5b7758
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
// Default is 30kB, let's set it to 5kB
minSize: 5000,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// Get the package name, e.g. node_modules/packageName
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
// npm package names are URL-safe, but some servers don't like @ symbols
return `npm.${packageName.replace('@', '')}`;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment