@@ -22,13 +22,20 @@ function versionInfo() {
22
22
"webpack " + require ( "webpack/package.json" ) . version ;
23
23
}
24
24
25
- function colorize ( useColor , msg ) {
25
+ function colorInfo ( useColor , msg ) {
26
26
if ( useColor )
27
27
// Make text blue and bold, so it *pops*
28
28
return "\u001b[1m\u001b[34m" + msg + "\u001b[39m\u001b[22m" ;
29
29
return msg ;
30
30
}
31
31
32
+ function colorError ( useColor , msg ) {
33
+ if ( useColor )
34
+ // Make text red and bold, so it *pops*
35
+ return "\u001b[1m\u001b[31m" + msg + "\u001b[39m\u001b[22m" ;
36
+ return msg ;
37
+ }
38
+
32
39
var yargs = require ( "yargs" )
33
40
. usage ( versionInfo ( ) +
34
41
"\nUsage: http://webpack.github.io/docs/webpack-dev-server.html" ) ;
@@ -320,15 +327,13 @@ function processOptions(wpOpt) {
320
327
}
321
328
322
329
var compiler ;
330
+ // TODO: This is only temporarily, we'll probably make our own ValidationError for WDS errors.
331
+ var WebpackOptionsValidationError = require ( "webpack/lib/WebpackOptionsValidationError" ) ;
323
332
try {
324
333
compiler = webpack ( wpOpt ) ;
325
334
} catch ( e ) {
326
- var WebpackOptionsValidationError = require ( "webpack/lib/WebpackOptionsValidationError" ) ;
327
335
if ( e instanceof WebpackOptionsValidationError ) {
328
- if ( options . stats . colors )
329
- console . error ( "\u001b[1m\u001b[31m" + e . message + "\u001b[39m\u001b[22m" ) ;
330
- else
331
- console . error ( e . message ) ;
336
+ console . error ( colorError ( options . stats . colors , e . message ) ) ;
332
337
process . exit ( 1 ) ; // eslint-disable-line
333
338
}
334
339
throw e ;
@@ -342,7 +347,16 @@ function processOptions(wpOpt) {
342
347
343
348
var uri = domain + ( options . inline !== false ? "/" : "/webpack-dev-server/" ) ;
344
349
345
- var server = new Server ( compiler , options ) ;
350
+ var server ;
351
+ try {
352
+ server = new Server ( compiler , options ) ;
353
+ } catch ( e ) {
354
+ if ( e instanceof WebpackOptionsValidationError ) {
355
+ console . error ( colorError ( options . stats . colors , e . message ) ) ;
356
+ process . exit ( 1 ) ; // eslint-disable-line
357
+ }
358
+ throw e ;
359
+ }
346
360
347
361
if ( options . socket ) {
348
362
server . listeningApp . on ( "error" , function ( e ) {
@@ -380,18 +394,18 @@ function processOptions(wpOpt) {
380
394
381
395
function reportReadiness ( uri , options ) {
382
396
var useColor = options . stats . colors ;
383
- var startSentence = "Project is running at " + colorize ( useColor , uri )
397
+ var startSentence = "Project is running at " + colorInfo ( useColor , uri )
384
398
if ( options . socket ) {
385
- startSentence = "Listening to socket at " + colorize ( useColor , options . socket ) ;
399
+ startSentence = "Listening to socket at " + colorInfo ( useColor , options . socket ) ;
386
400
}
387
401
console . log ( ( argv [ "progress" ] ? "\n" : "" ) + startSentence ) ;
388
402
389
- console . log ( "webpack output is served from " + colorize ( useColor , options . publicPath ) ) ;
403
+ console . log ( "webpack output is served from " + colorInfo ( useColor , options . publicPath ) ) ;
390
404
var contentBase = Array . isArray ( options . contentBase ) ? options . contentBase . join ( ", " ) : options . contentBase ;
391
405
if ( contentBase )
392
- console . log ( "Content not from webpack is served from " + colorize ( useColor , contentBase ) ) ;
406
+ console . log ( "Content not from webpack is served from " + colorInfo ( useColor , contentBase ) ) ;
393
407
if ( options . historyApiFallback )
394
- console . log ( "404s will fallback to " + colorize ( useColor , options . historyApiFallback . index || "/index.html" ) ) ;
408
+ console . log ( "404s will fallback to " + colorInfo ( useColor , options . historyApiFallback . index || "/index.html" ) ) ;
395
409
if ( options . open )
396
410
open ( uri ) ;
397
411
}
0 commit comments