misc: improve --generate option

static version will be generated and auto open + json stats
This commit is contained in:
Pooya Parsa 2018-03-27 11:22:22 +04:30
parent 47281c2761
commit b8d30d806a
2 changed files with 15 additions and 5 deletions

View File

@ -60,9 +60,11 @@ nuxt.hook('error', (_err, from) => Utils.fatalError(_err, from))
// Close function
const close = () => {
if (options.build.analyze === true) {
return // Wait for user exit
// In analyze mode wait for plugin opening the browser
if (options.build.analyze === true && !(this.options.ci || this.options.test)) {
return
}
process.exit(0)
}

View File

@ -66,10 +66,18 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
}
// Webpack Bundle Analyzer
// https://github.com/webpack-contrib/webpack-bundle-analyzer
if (!this.options.dev && this.options.build.analyze) {
plugins.push(
new BundleAnalyzer.BundleAnalyzerPlugin(Object.assign({}, this.options.build.analyze))
)
const statsDir = path.resolve(this.options.buildDir, 'stats')
plugins.push(new BundleAnalyzer.BundleAnalyzerPlugin(Object.assign({
analyzerMode: 'static',
defaultSizes: 'gzip',
generateStatsFile: true,
openAnalyzer: !(this.options.ci || this.options.test),
reportFilename: path.resolve(statsDir, 'client.html'),
statsFilename: path.resolve(statsDir, 'client.json')
}, this.options.build.analyze)))
}
return plugins