refactor: move stats to stats plugin

UX: warns from friendly error now come after stats
This commit is contained in:
Pooya Parsa 2018-03-22 15:01:23 +04:30 committed by Pooya Parsa
parent de847a7cd0
commit fd9672e51d
3 changed files with 39 additions and 28 deletions

View File

@ -534,15 +534,6 @@ export default class Builder {
console.error(err) // eslint-disable-line no-console
return reject(err)
}
if (!this.options.test) {
process.stdout.write(
'\n' +
stats.toString(this.options.build.stats) +
'\n'
)
}
resolve()
})
})

View File

@ -4,14 +4,15 @@ import FriendlyErrorsWebpackPlugin from '@nuxtjs/friendly-errors-webpack-plugin'
import TimeFixPlugin from 'time-fix-plugin'
import webpack from 'webpack'
import _ from 'lodash'
import VueLoader from 'vue-loader'
import { isUrl, urlJoin } from '../../common/utils'
import customLoaders from './loaders'
import styleLoaderWrapper from './style-loader'
import WarnFixPlugin from './plugins/warnfix'
import ProgressPlugin from './plugins/progress'
import styleLoaderWrapper from './style-loader'
import StatsPlugin from './plugins/stats'
/*
|--------------------------------------------------------------------------
@ -130,8 +131,16 @@ export default function webpackBaseConfig({ name, isServer }) {
].concat(this.options.build.plugins || [])
}
// Build progress indicator
// Add timefix-plugin before others plugins
if (this.options.dev) {
config.plugins.unshift(new TimeFixPlugin())
}
// Hide warnings about plugins without a default export (#1179)
config.plugins.push(new WarnFixPlugin())
if (!this.options.test) {
// Build progress indicator
if (this.options.build.profile) {
config.plugins.push(new webpack.ProgressPlugin({ profile: true }))
} else {
@ -143,15 +152,9 @@ export default function webpackBaseConfig({ name, isServer }) {
}))
}
}
}
// Add timefix-plugin before others plugins
if (this.options.dev) {
config.plugins.unshift(new TimeFixPlugin())
}
// Hide warnings about plugins without a default export (#1179)
config.plugins.push(new WarnFixPlugin())
// Add stats plugin
config.plugins.push(new StatsPlugin(this.options.build.stats))
// Add friendly error plugin
config.plugins.push(
@ -160,6 +163,7 @@ export default function webpackBaseConfig({ name, isServer }) {
logLevel: 'WARNING'
})
)
}
// Clone deep avoid leaking config between Client and Server
return _.cloneDeep(config)

View File

@ -0,0 +1,16 @@
export default class StatsPlugin {
constructor(statsOptions) {
this.statsOptions = statsOptions
}
apply(compiler) {
compiler.hooks.done.tap('stats-plugin', stats => {
process.stdout.write(
'\n' +
stats.toString(this.statsOptions) +
'\n'
)
})
}
}