1.安装
代码语言:javascript复制npm intall webpack-bundle-analyzer
2.vue.config.js中配置
代码语言:javascript复制 chainWebpack: config => {
if(process.env.NODE_ENV === 'production'){
if(process.env.npm_config_report){
config.plugin('webpack-bundle-analyzer')
.use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
.end();
config.plugins.delete('prefetch');
}
}
}
3.package.json scripts中添加
代码语言:javascript复制 "analyze":"cross-env NODE_ENV=production npm_config_report=true npm run build"
或者
"analyze": "npm_config_report=true npm run build"
4.运行
代码语言:javascript复制npm run analyze