22
33'use strict' ;
44
5- /* eslint-disable
6- import/order,
7- no-shadow,
8- no-console
9- */
10- const debug = require ( 'debug' ) ( 'webpack-dev-server' ) ;
5+ /* eslint-disable no-shadow, no-console */
116
127const fs = require ( 'fs' ) ;
138const net = require ( 'net' ) ;
14-
9+ const debug = require ( 'debug' ) ( 'webpack-dev-server' ) ;
1510const importLocal = require ( 'import-local' ) ;
16-
1711const yargs = require ( 'yargs' ) ;
1812const webpack = require ( 'webpack' ) ;
19-
20- const options = require ( './options' ) ;
2113const Server = require ( '../lib/Server' ) ;
22-
14+ const setupExitSignals = require ( '../lib/utils/setupExitSignals' ) ;
2315const colors = require ( '../lib/utils/colors' ) ;
24- const createConfig = require ( '../lib/utils/createConfig ' ) ;
16+ const processOptions = require ( '../lib/utils/processOptions ' ) ;
2517const createLogger = require ( '../lib/utils/createLogger' ) ;
2618const findPort = require ( '../lib/utils/findPort' ) ;
2719const getVersions = require ( '../lib/utils/getVersions' ) ;
20+ const options = require ( './options' ) ;
2821
2922let server ;
3023
31- // Taken out of yargs because we must know if
32- // it wasn't given by the user, in which case
33- // we should use portfinder.
34- const DEFAULT_PORT = 8080 ;
35-
36- const signals = [ 'SIGINT' , 'SIGTERM' ] ;
37-
38- signals . forEach ( ( signal ) => {
39- process . on ( signal , ( ) => {
40- if ( server ) {
41- server . close ( ( ) => {
42- // eslint-disable-next-line no-process-exit
43- process . exit ( ) ;
44- } ) ;
45- } else {
46- // eslint-disable-next-line no-process-exit
47- process . exit ( ) ;
48- }
49- } ) ;
50- } ) ;
24+ setupExitSignals ( server ) ;
5125
5226// Prefer the local installation of webpack-dev-server
5327if ( importLocal ( __filename ) ) {
@@ -106,22 +80,6 @@ const config = require(convertArgvPath)(yargs, argv, {
10680 outputFilename : '/bundle.js' ,
10781} ) ;
10882
109- function processOptions ( config ) {
110- // processOptions {Promise}
111- if ( typeof config . then === 'function' ) {
112- config . then ( processOptions ) . catch ( ( err ) => {
113- console . error ( err . stack || err ) ;
114- // eslint-disable-next-line no-process-exit
115- process . exit ( ) ;
116- } ) ;
117-
118- return ;
119- }
120-
121- const options = createConfig ( config , argv , { port : DEFAULT_PORT } ) ;
122- startDevServer ( config , options ) ;
123- }
124-
12583function startDevServer ( config , options ) {
12684 const log = createLogger ( options ) ;
12785
@@ -185,6 +143,7 @@ function startDevServer(config, options) {
185143 if ( err ) {
186144 throw err ;
187145 }
146+
188147 // chmod 666 (rw rw rw)
189148 const READ_WRITE = 438 ;
190149
@@ -210,4 +169,6 @@ function startDevServer(config, options) {
210169 }
211170}
212171
213- processOptions ( config ) ;
172+ processOptions ( config , argv , ( config , options ) => {
173+ startDevServer ( config , options ) ;
174+ } ) ;
0 commit comments