webpack打包分析工具(webpack-bundle-analyzer)安裝

joshinrai發表於2019-07-22

安裝

    npm install --save-dev webpack-bundle-analyzer
複製程式碼

配置(webpack.config.js)

    const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
    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新增

    "analyz": "NODE_ENV=production npm_config_report=true npm run build"
複製程式碼

執行

npm run analyz複製程式碼

相關文章