安装webpack-bundle-analyzer

npm install --save-dev webpack-bundle-analyzer

解决 ‘NODE_ENV’ 不是内部或外部命令,也不是可运行的程序或批处理文件 的报错

npm install cross-env –save -dev

配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
configureWebpack: {
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: "server",
analyzerHost: "127.0.0.1",
analyzerPort: 8888,
reportFilename: "report.html",
defaultSizes: "parsed",
openAnalyzer: true,
generateStatsFile: false,
statsFilename: "stats.json",
statsOptions: null,
logLevel: "info"
})
]
}

package.json

1
2
3
4
5
6
7
8
9
10
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --open --hot",
"start": "npm run dev",
"unit": "jest --config test/unit/jest.conf.js --coverage",
"e2e": "node test/e2e/runner.js",
"test": "npm run unit && npm run e2e",
"lint": "eslint --ext .js,.vue src test/unit test/e2e/specs",
"build": "node build/build.js",
"analyz": "cross-env NODE_ENV=production npm_config_report=true npm run build"
}

npm run analyz