add generateAnalyzerReport

This commit is contained in:
Pan 2018-07-24 11:40:58 +08:00
parent 3da56b1a44
commit 7df8eaf064
2 changed files with 18 additions and 4 deletions

View File

@ -67,7 +67,7 @@ const webpackConfig = merge(baseWebpackConfig, {
}), }),
new ScriptExtHtmlWebpackPlugin({ new ScriptExtHtmlWebpackPlugin({
//`runtime` must same as runtimeChunk name. default is `runtime` //`runtime` must same as runtimeChunk name. default is `runtime`
inline:/runtime\..*\.js$/ inline: /runtime\..*\.js$/
}), }),
// keep module.id stable when vender modules does not change // keep module.id stable when vender modules does not change
new webpack.HashedModuleIdsPlugin(), new webpack.HashedModuleIdsPlugin(),
@ -151,9 +151,22 @@ if (config.build.productionGzip) {
) )
} }
if (config.build.bundleAnalyzerReport) { if (config.build.generateAnalyzerReport || config.build.bundleAnalyzerReport) {
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
webpackConfig.plugins.push(new BundleAnalyzerPlugin())
if (config.build.bundleAnalyzerReport) {
webpackConfig.plugins.push(new BundleAnalyzerPlugin({
analyzerPort: 8080,
generateStatsFile: false
}))
}
if (config.build.generateAnalyzerReport) {
webpackConfig.plugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false
}))
}
} }
module.exports = webpackConfig module.exports = webpackConfig

View File

@ -86,6 +86,7 @@ module.exports = {
// View the bundle analyzer report after build finishes: // View the bundle analyzer report after build finishes:
// `npm run build --report` // `npm run build --report`
// Set to `true` or `false` to always turn it on or off // Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report bundleAnalyzerReport: process.env.npm_config_report || false,
generateAnalyzerReport: process.env.npm_config_generate_report || false
} }
} }