优化moment.js的体积
//在vue-cli3 使用方式:配置vue.config.js的configureWebpack
const webpack = require("webpack");
configureWebpack: {
entry: isDev ? [projectThemeEntry, './src/main'] : './src/main',
devtool: '#cheap-module-eval-source-map',
plugins: [
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /zh-cn|en-gb/),
]
}
splitChunks
config.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
vendor: {
name: 'chunk-vendors',
minChunks: 1,
test: /[\\/]node_modules[\\/]/,
priority: 20,
chunks: 'initial'
},
hui: {
name: 'chunk-hui', // 单独将 echarts 拆包
priority: 30,
test: /[\\/]node_modules[\\/]hui[\\/]/,
chunks: 'all'
},
echarts: {
name: 'chunk-echarts', // 单独将 echarts 拆包
priority: 30,
test: /[\\/]node_modules[\\/]echarts[\\/]/,
chunks: 'all'
}
}
});
chunks
- async:默认, 把动态模块打包进 vendor
- initial:都分开
- all::把动态和非动态模块块都扔到 一个vendors里面
minChunks: 引入次数,如果为2 那么一个资源最少被引用两次才可以被拆分出来
- 非常好,可以参考