From bd28ef1ac38bf342269f89bbc978d59146909de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E9=A2=A2?= Date: Wed, 9 Jan 2019 11:44:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20devCompilerExtensio?= =?UTF-8?q?ns=20=E6=8A=A5=E9=94=99=E9=9C=80=E8=A6=81=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/compiler.webpack.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/utils/compiler.webpack.ts b/src/utils/compiler.webpack.ts index 0d6b7b2..3b6f3a2 100644 --- a/src/utils/compiler.webpack.ts +++ b/src/utils/compiler.webpack.ts @@ -11,7 +11,7 @@ import { readFileSync, existsSync } from 'fs' import { Express } from 'express' import { routerStackManagement } from 'src/utils' -function showError(stats: webpack.Stats) { +function showError(stats: webpack.Stats, { isdev }: { isdev?: boolean } = {}) { if (stats.hasWarnings()) { stats.compilation.warnings.forEach(warning => { consola.info(warning) @@ -21,7 +21,7 @@ function showError(stats: webpack.Stats) { stats.compilation.errors.forEach(error => { consola.fatal(error) }) - return process.exit(0) + if (!isdev) return process.exit(0) } } @@ -160,7 +160,7 @@ export function compilerConfig( ): Promise<() => webpack.Configuration> { return new Promise(function(this: any, done) { const webpackConfig = getConfigConfig({ rootDir }) - const entryName = `${mode === 'none'? 'production': mode}_config` + const entryName = `${mode === 'none' ? 'production' : mode}_config` const { entry, output } = configOptions if (!(entry && output)) { @@ -327,7 +327,7 @@ function devCompilerExtensions(options: ConfigOptions.options, app?: Express) { const compiler = getCompiler(webpackConfig) const serverDevMiddleware = require('webpack-dev-middleware')(compiler, { noInfo: true, - logLevel: 'silent', + logLevel: 'silent' }) app.use(serverDevMiddleware) @@ -336,11 +336,7 @@ function devCompilerExtensions(options: ConfigOptions.options, app?: Express) { compiler.plugin('done', function(this: any, stats) { routerStackManagement.init(app) - stats = stats.toJson() - if (stats.errors.length) { - showError(stats) - return process.exit(0) - } + showError(stats, { isdev: true }) Object.keys(entrys).forEach(entry => { const name = entry + '.js' @@ -369,6 +365,6 @@ function devCompilerExtensions(options: ConfigOptions.options, app?: Express) { * @param config webpack 配置文件 */ function getCompiler(config: webpack.Configuration) { - consola.info('Working Compiler:', config.name , '\n') + consola.info('Working Compiler:', config.name, '\n') return webpack(config) -} \ No newline at end of file +}