|
@@ -123,6 +123,55 @@ const vueConfig = {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ config.optimization && config.optimization.splitChunks({
|
|
|
+ // 拆包配置
|
|
|
+ chunks: 'all', //三选一:"initial" 初始化,"all"(默认就是all),"async"(动态加载)
|
|
|
+ minSize: 30000, // 形成一个新代码块最小的体积,只有 >= minSize 的bundle会被拆分出来 30000
|
|
|
+ maxSize: 0, //拆分之前最大的数值,默认为0,即不做限制
|
|
|
+ minChunks: 1, //引入次数,如果为2 那么一个资源最少被引用两次才可以被拆分出来
|
|
|
+ maxAsyncRequests: 5, // 按需加载的最大并行请求数
|
|
|
+ maxInitialRequests: 3, // 一个入口最大并行请求数
|
|
|
+ automaticNameDelimiter: '~', // 文件名的连接符
|
|
|
+ name: true,
|
|
|
+ cacheGroups: {
|
|
|
+ // node_modules模块包
|
|
|
+ vendors: {
|
|
|
+ test: /[\\/]node_modules[\\/]/,
|
|
|
+ name: 'chunk-vendors',
|
|
|
+ // name(module) {
|
|
|
+ // const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
|
|
|
+ // return `chunk.${packageName.replace('@', '')}`;
|
|
|
+ // },
|
|
|
+ chunks: 'all',
|
|
|
+ priority: -10,
|
|
|
+ },
|
|
|
+ // UI库单独拆包
|
|
|
+ elementUI: {
|
|
|
+ name: 'chunk-antDesignVue',
|
|
|
+ priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
|
|
|
+ test: /[\\/]node_modules[\\/]_?ant-design-vue(.*)/
|
|
|
+ },
|
|
|
+ videoJs: {
|
|
|
+ name: 'chunk-videoJs',
|
|
|
+ priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
|
|
|
+ test: /[\\/]node_modules[\\/]_?video(.*)/
|
|
|
+ },
|
|
|
+ vScroll: {
|
|
|
+ name: 'chunk-vuescroll',
|
|
|
+ priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
|
|
|
+ test: /[\\/]node_modules[\\/]_?vuescroll(.*)/
|
|
|
+ },
|
|
|
+ // 共享模块
|
|
|
+ common: {
|
|
|
+ name: 'chunk-common',
|
|
|
+ minChunks: 2,
|
|
|
+ maxSize: 1024, //拆分之前最大的数值,默认为0,即不做限制
|
|
|
+ priority: -20,
|
|
|
+ reuseExistingChunk: true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
// 分析打包大小
|
|
|
if (process.env.npm_config_report) {
|
|
|
config.plugin('webpack-bundle-analyzer')
|