前言
npm
: webpack-bundle-analyzer
github
:webpack-bundle-analyzer
内容
安装
代码语言:javascript复制npm i -D webpack-bundle-analyzer
配置
主要涉及两个文件webpack.config.js
和package.json
webpack.config.js
代码语言:javascript复制const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
module.exports = {
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'disabled',
generateStatsFile: true,
}),
],
}
package.json
代码语言:javascript复制{
"scripts": {
"analyz": "webpack --profile --json > stats.json && webpack-bundle-analyzer --port 9090 ./dist/stats.json"
},
}
测试
运行命令
代码语言:javascript复制npm run analyz