Skip to content

Instantly share code, notes, and snippets.

@walokra
Last active March 31, 2023 17:20
Show Gist options
  • Select an option

  • Save walokra/78152f0c776a9bcab2dc2531eb7c5b5d to your computer and use it in GitHub Desktop.

Select an option

Save walokra/78152f0c776a9bcab2dc2531eb7c5b5d to your computer and use it in GitHub Desktop.
vue-cli v5 and Webpack vendor split packages
module.exports = {
productionSourceMap: false,
configureWebpack: {
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
minSize: 0,
maxInitialRequests: Infinity,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module, chunks, cacheGroupKey) {
// get the name. E.g. node_modules/packageName/not/this/part.js
// or node_modules/packageName
const match = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)
// the above might cause filename collisions if you have multiple packages from the same scope.
// then use: /[\\/]node_modules[\\/](?:(@[\w-]*?[\\/].*?|.*?)([\\/]|$))/
if (match) {
const packageName = match[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