vue(typescript) 使用webpack-bundle-analyzer

2020-08-28 17:11:06 浏览数 (1)

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

0 人点赞