title: webpack-bundle-analyzer分析打包文件
tags:
- Vue-cli3.0
- webpack
categories: - 前端
date: 2019-08-29 00:00:00
- 安装:
npm install --save-dev webpack-bundle-analyzer
- 在
vue.config.js
中配置:
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
chainWebpack: config => {
// 打包分析
if (process.env.IS_ANALYZ) {
config.plugin('webpack-report')
.use(BundleAnalyzerPlugin, [{
analyzerMode: 'static',
}]);
}
}
}
配置的时候可以根据实际需要修改分析报告,参考:https://github.com/webpack-contrib/webpack-bundle-analyzer,比如:
config.plugin('webpack-report')
.use(BundleAnalyzerPlugin, [{
analyzerMode: 'server',
analyzerHost: '127.0.0.1',
analyzerPort: 8889,
reportFilename: 'report.html',
defaultSizes: 'parsed',
openAnalyzer: true,
generateStatsFile: false,
statsFilename: 'stats.json',
statsOptions: null,
logLevel: 'info'
}])
- 生成打包模块大小相关的报告: