2
2
3
3
'use strict' ;
4
4
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 */
11
6
12
7
const fs = require ( 'fs' ) ;
13
8
const net = require ( 'net' ) ;
14
-
9
+ const debug = require ( 'debug' ) ( 'webpack-dev-server' ) ;
15
10
const importLocal = require ( 'import-local' ) ;
16
-
17
11
const yargs = require ( 'yargs' ) ;
18
12
const webpack = require ( 'webpack' ) ;
19
-
20
- const options = require ( './options' ) ;
21
13
const Server = require ( '../lib/Server' ) ;
22
-
14
+ const setupExitSignals = require ( '../lib/utils/setupExitSignals' ) ;
23
15
const colors = require ( '../lib/utils/colors' ) ;
24
- const createConfig = require ( '../lib/utils/createConfig ' ) ;
16
+ const processOptions = require ( '../lib/utils/processOptions ' ) ;
25
17
const createLogger = require ( '../lib/utils/createLogger' ) ;
26
18
const findPort = require ( '../lib/utils/findPort' ) ;
27
19
const getVersions = require ( '../lib/utils/getVersions' ) ;
20
+ const options = require ( './options' ) ;
28
21
29
22
let server ;
30
23
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 ) ;
51
25
52
26
// Prefer the local installation of webpack-dev-server
53
27
if ( importLocal ( __filename ) ) {
@@ -106,22 +80,6 @@ const config = require(convertArgvPath)(yargs, argv, {
106
80
outputFilename : '/bundle.js' ,
107
81
} ) ;
108
82
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
-
125
83
function startDevServer ( config , options ) {
126
84
const log = createLogger ( options ) ;
127
85
@@ -185,6 +143,7 @@ function startDevServer(config, options) {
185
143
if ( err ) {
186
144
throw err ;
187
145
}
146
+
188
147
// chmod 666 (rw rw rw)
189
148
const READ_WRITE = 438 ;
190
149
@@ -210,4 +169,6 @@ function startDevServer(config, options) {
210
169
}
211
170
}
212
171
213
- processOptions ( config ) ;
172
+ processOptions ( config , argv , ( config , options ) => {
173
+ startDevServer ( config , options ) ;
174
+ } ) ;
0 commit comments