diff --git a/lib/builder/builder.js b/lib/builder/builder.js index cf9b127b71..50ced73699 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -282,36 +282,30 @@ export default class Builder extends Tapable { // Start Builds 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) { + // --- Dev Build --- if (compiler.options.name === 'client') { // Client watch is started by dev-middleware resolve() } else { // 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 { - // Production build - compiler.run(handler) + // --- Production build --- + 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() + }) } })) }