参考WebPack split-chunks-plugin插件配置教程!!!
1.修改配置文件vue.config.js
// vue.config.js 配置说明
module.exports = {
// webpack的配置在这个属性里修改configureWebpack
configureWebpack: config => {
if (process.env.NODE_ENV === 'development') {
config.devtool = 'source-map';
// mutate config for production...
} else {
/**
* @link https://webpack.js.org/plugins/split-chunks-plugin/#root
* @type {{splitChunks: {cacheGroups: {xdfsdk: {name: string, test: RegExp, priority: number, chunks: string}}}}}
* @priority 优先执行权重 chunk-vendors: -10 chunk-common: -20
* @chunks initial(初始块)、async(按需加载块)、all(全部块)
*/
config.optimization = {
splitChunks: {
cacheGroups: {
vendors: {
name: `chunk-vendors`,
test: /[\\/]node_modules[\\/]/,
priority: -10,
chunks: 'initial'
},
common: {
name: `chunk-common`,
minChunks: 2,
priority: -20,
chunks: 'initial',
reuseExistingChunk: true
},
newsdk: {
name: 'new-sdk-config',
test: /new-sdk/, // src 项目下的文件夹,对该文件jia
minChunks: 1,
minSize: 0,
chunks: 'async',
priority: 60,
reuseExistingChunk: true
}
}
}
}
}
},
// 第三方插件配置
pluginOptions: {}
}