首先要下载插件,运行下面代码看看有没有webpack-bundle-analyzer
npm list webpack-bundle-analyzer
没有安装就安装
npm install --save-dev webpack-bundle-analyzer
在这个文件 build/webpack.prod.conf.js
下
if (config.build.bundleAnalyzerReport) {
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
webpackConfig.plugins.push(new BundleAnalyzerPlugin())
}
在 package.json
文件中的 "scripts"
部分添加一个新的命令,例如 "analyze": "NODE_ENV=production npm_config_report=true npm run build"
. 这个命令会在构建完成后自动打开一个浏览器页面生成分析报告。
"analyz": "vue-cli-service build --mode analyz"
然后运行npm run build --report
npm run build --report