1
1
#!/usr/bin/env node
2
+ "use strict" ;
2
3
3
- var path = require ( "path" ) ;
4
- var open = require ( "opn" ) ;
5
- var fs = require ( "fs" ) ;
6
- var net = require ( "net" ) ;
7
- var url = require ( "url" ) ;
8
- var portfinder = require ( "portfinder" ) ;
4
+ const path = require ( "path" ) ;
5
+ const open = require ( "opn" ) ;
6
+ const fs = require ( "fs" ) ;
7
+ const net = require ( "net" ) ;
8
+ const url = require ( "url" ) ;
9
+ const portfinder = require ( "portfinder" ) ;
9
10
10
11
// Local version replaces global one
11
12
try {
12
- var localWebpackDevServer = require . resolve ( path . join ( process . cwd ( ) , "node_modules" , "webpack-dev-server" , "bin" , "webpack-dev-server.js" ) ) ;
13
+ const localWebpackDevServer = require . resolve ( path . join ( process . cwd ( ) , "node_modules" , "webpack-dev-server" , "bin" , "webpack-dev-server.js" ) ) ;
13
14
if ( __filename !== localWebpackDevServer ) {
14
15
return require ( localWebpackDevServer ) ;
15
16
}
16
17
} catch ( e ) { }
17
18
18
- var Server = require ( "../lib/Server" ) ;
19
- var webpack = require ( "webpack" ) ;
19
+ const Server = require ( "../lib/Server" ) ;
20
+ const webpack = require ( "webpack" ) ;
20
21
21
22
function versionInfo ( ) {
22
- return " webpack-dev-server " + require ( "../package.json" ) . version + "\n" +
23
- " webpack " + require ( "webpack/package.json" ) . version ;
23
+ return ` webpack-dev-server ${ require ( "../package.json" ) . version } \n` +
24
+ ` webpack ${ require ( "webpack/package.json" ) . version } ` ;
24
25
}
25
26
26
27
function colorInfo ( useColor , msg ) {
27
28
if ( useColor )
28
29
// Make text blue and bold, so it *pops*
29
- return " \u001b[1m\u001b[34m" + msg + " \u001b[39m\u001b[22m" ;
30
+ return ` \u001b[1m\u001b[34m${ msg } \u001b[39m\u001b[22m` ;
30
31
return msg ;
31
32
}
32
33
33
34
function colorError ( useColor , msg ) {
34
35
if ( useColor )
35
36
// Make text red and bold, so it *pops*
36
- return " \u001b[1m\u001b[31m" + msg + " \u001b[39m\u001b[22m" ;
37
+ return ` \u001b[1m\u001b[31m${ msg } \u001b[39m\u001b[22m` ;
37
38
return msg ;
38
39
}
39
40
40
- var yargs = require ( "yargs" )
41
- . usage ( versionInfo ( ) +
42
- " \nUsage: http://webpack.github.io/docs/webpack-dev-server.html" ) ;
41
+ const yargs = require ( "yargs" )
42
+ . usage ( ` ${ versionInfo ( )
43
+ } \nUsage: http://webpack.github.io/docs/webpack-dev-server.html` ) ;
43
44
44
45
require ( "webpack/bin/config-yargs" ) ( yargs ) ;
45
46
46
47
// It is important that this is done after the webpack yargs config,
47
48
// so it overrides webpack's version info.
48
49
yargs . version ( versionInfo ) ;
49
50
50
- var ADVANCED_GROUP = "Advanced options:" ;
51
- var DISPLAY_GROUP = "Stats options:" ;
52
- var SSL_GROUP = "SSL options:" ;
53
- var CONNECTION_GROUP = "Connection options:" ;
54
- var RESPONSE_GROUP = "Response options:" ;
55
- var BASIC_GROUP = "Basic options:" ;
51
+ const ADVANCED_GROUP = "Advanced options:" ;
52
+ const DISPLAY_GROUP = "Stats options:" ;
53
+ const SSL_GROUP = "SSL options:" ;
54
+ const CONNECTION_GROUP = "Connection options:" ;
55
+ const RESPONSE_GROUP = "Response options:" ;
56
+ const BASIC_GROUP = "Basic options:" ;
56
57
57
58
// Taken out of yargs because we must know if
58
59
// it wasn't given by the user, in which case
59
60
// we should use portfinder.
60
- var DEFAULT_PORT = 8080 ;
61
+ const DEFAULT_PORT = 8080 ;
61
62
62
63
yargs . options ( {
63
64
"lazy" : {
@@ -185,9 +186,9 @@ yargs.options({
185
186
}
186
187
} ) ;
187
188
188
- var argv = yargs . argv ;
189
+ const argv = yargs . argv ;
189
190
190
- var wpOpt = require ( "webpack/bin/convert-argv" ) ( yargs , argv , {
191
+ const wpOpt = require ( "webpack/bin/convert-argv" ) ( yargs , argv , {
191
192
outputFilename : "/bundle.js"
192
193
} ) ;
193
194
@@ -201,9 +202,9 @@ function processOptions(wpOpt) {
201
202
return ;
202
203
}
203
204
204
- var firstWpOpt = Array . isArray ( wpOpt ) ? wpOpt [ 0 ] : wpOpt ;
205
+ const firstWpOpt = Array . isArray ( wpOpt ) ? wpOpt [ 0 ] : wpOpt ;
205
206
206
- var options = wpOpt . devServer || firstWpOpt . devServer || { } ;
207
+ const options = wpOpt . devServer || firstWpOpt . devServer || { } ;
207
208
208
209
if ( argv . host !== "localhost" || ! options . host )
209
210
options . host = argv . host ;
@@ -217,7 +218,7 @@ function processOptions(wpOpt) {
217
218
if ( ! options . publicPath ) {
218
219
options . publicPath = firstWpOpt . output && firstWpOpt . output . publicPath || "" ;
219
220
if ( ! / ^ ( h t t p s ? : ) ? \/ \/ / . test ( options . publicPath ) && options . publicPath [ 0 ] !== "/" )
220
- options . publicPath = "/" + options . publicPath ;
221
+ options . publicPath = `/ ${ options . publicPath } ` ;
221
222
}
222
223
223
224
if ( ! options . filename )
@@ -326,17 +327,17 @@ function processOptions(wpOpt) {
326
327
}
327
328
328
329
function startDevServer ( wpOpt , options ) {
329
- var protocol = options . https ? "https" : "http" ;
330
+ const protocol = options . https ? "https" : "http" ;
330
331
331
332
// the formatted domain (url without path) of the webpack server
332
- var domain = url . format ( {
333
+ const domain = url . format ( {
333
334
protocol : protocol ,
334
335
hostname : options . host ,
335
336
port : options . socket ? 0 : options . port . toString ( )
336
337
} ) ;
337
338
338
339
if ( options . inline !== false ) {
339
- var devClient = [ require . resolve ( "../client/" ) + "?" + ( options . public ? protocol + " ://" + options . public : domain ) ] ;
340
+ const devClient = [ ` ${ require . resolve ( "../client/" ) } ? ${ options . public ? ` ${ protocol } ://${ options . public } ` : domain } ` ] ;
340
341
341
342
if ( options . hotOnly )
342
343
devClient . push ( "webpack/hot/only-dev-server" ) ;
@@ -354,7 +355,7 @@ function startDevServer(wpOpt, options) {
354
355
} ) ;
355
356
}
356
357
357
- var compiler ;
358
+ let compiler ;
358
359
try {
359
360
compiler = webpack ( wpOpt ) ;
360
361
} catch ( e ) {
@@ -371,13 +372,13 @@ function startDevServer(wpOpt, options) {
371
372
} ) ) ;
372
373
}
373
374
374
- var uri = domain + ( options . inline !== false || options . lazy === true ? "/" : "/webpack-dev-server/" ) ;
375
+ const uri = domain + ( options . inline !== false || options . lazy === true ? "/" : "/webpack-dev-server/" ) ;
375
376
376
- var server ;
377
+ let server ;
377
378
try {
378
379
server = new Server ( compiler , options ) ;
379
380
} catch ( e ) {
380
- var OptionsValidationError = require ( "../lib/OptionsValidationError" ) ;
381
+ const OptionsValidationError = require ( "../lib/OptionsValidationError" ) ;
381
382
if ( e instanceof OptionsValidationError ) {
382
383
console . error ( colorError ( options . stats . colors , e . message ) ) ;
383
384
process . exit ( 1 ) ; // eslint-disable-line
@@ -388,7 +389,7 @@ function startDevServer(wpOpt, options) {
388
389
if ( options . socket ) {
389
390
server . listeningApp . on ( "error" , function ( e ) {
390
391
if ( e . code === "EADDRINUSE" ) {
391
- var clientSocket = new net . Socket ( ) ;
392
+ const clientSocket = new net . Socket ( ) ;
392
393
clientSocket . on ( "error" , function ( e ) {
393
394
if ( e . code === "ECONNREFUSED" ) {
394
395
// No other server listening on this socket so it can be safely removed
@@ -405,7 +406,7 @@ function startDevServer(wpOpt, options) {
405
406
} ) ;
406
407
server . listen ( options . socket , options . host , function ( err ) {
407
408
if ( err ) throw err ;
408
- var READ_WRITE = 438 ; // chmod 666 (rw rw rw)
409
+ const READ_WRITE = 438 ; // chmod 666 (rw rw rw)
409
410
fs . chmod ( options . socket , READ_WRITE , function ( err ) {
410
411
if ( err ) throw err ;
411
412
reportReadiness ( uri , options ) ;
@@ -420,19 +421,19 @@ function startDevServer(wpOpt, options) {
420
421
}
421
422
422
423
function reportReadiness ( uri , options ) {
423
- var useColor = argv . color ;
424
- var startSentence = " Project is running at " + colorInfo ( useColor , uri )
424
+ const useColor = argv . color ;
425
+ let startSentence = ` Project is running at ${ colorInfo ( useColor , uri ) } `
425
426
if ( options . socket ) {
426
- startSentence = " Listening to socket at " + colorInfo ( useColor , options . socket ) ;
427
+ startSentence = ` Listening to socket at ${ colorInfo ( useColor , options . socket ) } ` ;
427
428
}
428
429
console . log ( ( argv [ "progress" ] ? "\n" : "" ) + startSentence ) ;
429
430
430
- console . log ( " webpack output is served from " + colorInfo ( useColor , options . publicPath ) ) ;
431
- var contentBase = Array . isArray ( options . contentBase ) ? options . contentBase . join ( ", " ) : options . contentBase ;
431
+ console . log ( ` webpack output is served from ${ colorInfo ( useColor , options . publicPath ) } ` ) ;
432
+ const contentBase = Array . isArray ( options . contentBase ) ? options . contentBase . join ( ", " ) : options . contentBase ;
432
433
if ( contentBase )
433
- console . log ( " Content not from webpack is served from " + colorInfo ( useColor , contentBase ) ) ;
434
+ console . log ( ` Content not from webpack is served from ${ colorInfo ( useColor , contentBase ) } ` ) ;
434
435
if ( options . historyApiFallback )
435
- console . log ( " 404s will fallback to " + colorInfo ( useColor , options . historyApiFallback . index || "/index.html" ) ) ;
436
+ console . log ( ` 404s will fallback to ${ colorInfo ( useColor , options . historyApiFallback . index || "/index.html" ) } ` ) ;
436
437
if ( options . open )
437
438
open ( uri ) ;
438
439
}
0 commit comments