Last active
March 31, 2023 17:20
-
-
Save walokra/78152f0c776a9bcab2dc2531eb7c5b5d to your computer and use it in GitHub Desktop.
vue-cli v5 and Webpack vendor split packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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