Skip to content

Commit

Permalink
fix: 修复 devCompilerExtensions 报错需要提示错误信息
Browse files Browse the repository at this point in the history
  • Loading branch information
孙颢 committed Jan 9, 2019
1 parent ddf9915 commit bd28ef1
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/utils/compiler.webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)

Expand All @@ -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'
Expand Down Expand Up @@ -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)
}
}

0 comments on commit bd28ef1

Please sign in to comment.