simplify webpackBuild()

This commit is contained in:
Pooya Parsa 2017-06-18 16:20:43 +04:30
parent c61f40e16d
commit 1ff37506a7

View File

@ -282,36 +282,30 @@ export default class Builder extends Tapable {
// Start Builds // Start Builds
return parallel(this.compiler.compilers, compiler => new Promise((resolve, reject) => { return parallel(this.compiler.compilers, compiler => new Promise((resolve, reject) => {
let _resolved = false
const handler = (err, stats) => {
/* istanbul ignore if */
if (_resolved) {
return
}
_resolved = true
if (err) {
return reject(err)
}
if (!this.options.dev) {
// Show build stats for production
console.log(stats.toString(this.webpackStats)) // eslint-disable-line no-console
if (stats.hasErrors()) {
return reject(new Error('Webpack build exited with errors'))
}
}
resolve()
}
if (this.options.dev) { if (this.options.dev) {
// --- Dev Build ---
if (compiler.options.name === 'client') { if (compiler.options.name === 'client') {
// Client watch is started by dev-middleware // Client watch is started by dev-middleware
resolve() resolve()
} else { } else {
// Build and watch for changes // Build and watch for changes
compiler.watch(this.options.watchers.webpack, handler) compiler.watch(this.options.watchers.webpack, (err) => {
if (err) {
return reject(err)
}
resolve()
})
} }
} else { } else {
// Production build // --- Production build ---
compiler.run(handler) compiler.run((err, stats) => {
// Show build stats for production
console.log(stats.toString(this.webpackStats)) // eslint-disable-line no-console
if (stats.hasErrors()) {
return reject(new Error('Webpack build exited with errors'))
}
resolve()
})
} }
})) }))
} }