@@ -25,92 +25,18 @@ function normalizeOptions(compiler, options, logger, cacheDir) {
25
25
watch : watchOptions ,
26
26
} ;
27
27
28
- if ( typeof options . static === 'undefined' ) {
29
- options . static = [ defaultOptionsForStatic ] ;
30
- } else if ( typeof options . static === 'boolean' ) {
31
- options . static = options . static ? [ defaultOptionsForStatic ] : false ;
32
- } else if ( typeof options . static === 'string' ) {
33
- options . static = [
34
- { ...defaultOptionsForStatic , directory : options . static } ,
35
- ] ;
36
- } else if ( Array . isArray ( options . static ) ) {
37
- options . static = options . static . map ( ( item ) => {
38
- if ( typeof item === 'string' ) {
39
- return { ...defaultOptionsForStatic , directory : item } ;
40
- }
41
-
42
- return { ...defaultOptionsForStatic , ...item } ;
43
- } ) ;
44
- } else {
45
- options . static = [ { ...defaultOptionsForStatic , ...options . static } ] ;
46
- }
47
-
48
- if ( options . static ) {
49
- const isAbsoluteUrl = require ( 'is-absolute-url' ) ;
50
-
51
- options . static . forEach ( ( staticOption ) => {
52
- if ( isAbsoluteUrl ( staticOption . directory ) ) {
53
- throw new Error ( 'Using a URL as static.directory is not supported' ) ;
54
- }
55
-
56
- // ensure that publicPath is an array
57
- if ( typeof staticOption . publicPath === 'string' ) {
58
- staticOption . publicPath = [ staticOption . publicPath ] ;
59
- }
60
-
61
- // ensure that watch is an object if true
62
- if ( staticOption . watch === true ) {
63
- staticOption . watch = defaultOptionsForStatic . watch ;
64
- }
65
-
66
- // ensure that serveIndex is an object if true
67
- if ( staticOption . serveIndex === true ) {
68
- staticOption . serveIndex = defaultOptionsForStatic . serveIndex ;
69
- }
70
- } ) ;
71
- }
72
-
73
- options . hot =
74
- typeof options . hot === 'boolean' || options . hot === 'only'
75
- ? options . hot
76
- : true ;
77
- options . liveReload =
78
- typeof options . liveReload !== 'undefined' ? options . liveReload : true ;
79
-
80
- if ( typeof options . port === 'string' && options . port !== 'auto' ) {
81
- options . port = Number ( options . port ) ;
28
+ if ( typeof options . allowedHosts === 'undefined' ) {
29
+ // allowedHosts allows some default hosts picked from
30
+ // `options.host` or `webSocketURL.hostname` and `localhost`
31
+ options . allowedHosts = 'auto' ;
82
32
}
83
-
84
- const defaultWebSocketServerType = 'ws' ;
85
- const defaultWebSocketServerOptions = { path : '/ws' } ;
86
-
87
- if ( typeof options . webSocketServer === 'undefined' ) {
88
- options . webSocketServer = {
89
- type : defaultWebSocketServerType ,
90
- options : defaultWebSocketServerOptions ,
91
- } ;
92
- } else if (
93
- typeof options . webSocketServer === 'string' ||
94
- typeof options . webSocketServer === 'function'
33
+ if (
34
+ typeof options . allowedHosts === 'string' &&
35
+ options . allowedHosts !== 'auto' &&
36
+ options . allowedHosts !== 'all'
95
37
) {
96
- options . webSocketServer = {
97
- type : options . webSocketServer ,
98
- options : defaultWebSocketServerOptions ,
99
- } ;
100
- } else {
101
- options . webSocketServer = {
102
- type : options . webSocketServer . type || defaultWebSocketServerType ,
103
- options : {
104
- ...defaultWebSocketServerOptions ,
105
- ...options . webSocketServer . options ,
106
- } ,
107
- } ;
108
-
109
- if ( typeof options . webSocketServer . options . port === 'string' ) {
110
- options . webSocketServer . options . port = Number (
111
- options . webSocketServer . options . port
112
- ) ;
113
- }
38
+ // we store allowedHosts as array when supplied as string
39
+ options . allowedHosts = [ options . allowedHosts ] ;
114
40
}
115
41
116
42
if ( ! options . client ) {
@@ -150,30 +76,17 @@ function normalizeOptions(compiler, options, logger, cacheDir) {
150
76
options . client . hotEntry = options . hot ;
151
77
}
152
78
153
- options . devMiddleware = options . devMiddleware || { } ;
154
-
155
- if ( typeof options . allowedHosts === 'undefined' ) {
156
- // allowedHosts allows some default hosts picked from
157
- // `options.host` or `webSocketURL.hostname` and `localhost`
158
- options . allowedHosts = 'auto' ;
159
- }
160
- if (
161
- typeof options . allowedHosts === 'string' &&
162
- options . allowedHosts !== 'auto' &&
163
- options . allowedHosts !== 'all'
164
- ) {
165
- // we store allowedHosts as array when supplied as string
166
- options . allowedHosts = [ options . allowedHosts ] ;
167
- }
168
-
169
- if ( typeof options . setupExitSignals === 'undefined' ) {
170
- options . setupExitSignals = true ;
171
- }
172
-
173
79
if ( typeof options . compress === 'undefined' ) {
174
80
options . compress = true ;
175
81
}
176
82
83
+ options . devMiddleware = options . devMiddleware || { } ;
84
+
85
+ options . hot =
86
+ typeof options . hot === 'boolean' || options . hot === 'only'
87
+ ? options . hot
88
+ : true ;
89
+
177
90
// if the user enables http2, we can safely enable https
178
91
if ( ( options . http2 && ! options . https ) || options . https === true ) {
179
92
options . https = {
@@ -306,6 +219,13 @@ function normalizeOptions(compiler, options, logger, cacheDir) {
306
219
options . https . cert = options . https . cert || fakeCert ;
307
220
}
308
221
222
+ options . liveReload =
223
+ typeof options . liveReload !== 'undefined' ? options . liveReload : true ;
224
+
225
+ if ( typeof options . port === 'string' && options . port !== 'auto' ) {
226
+ options . port = Number ( options . port ) ;
227
+ }
228
+
309
229
/**
310
230
* Assume a proxy configuration specified as:
311
231
* proxy: {
@@ -373,6 +293,87 @@ function normalizeOptions(compiler, options, logger, cacheDir) {
373
293
}
374
294
}
375
295
}
296
+
297
+ if ( typeof options . setupExitSignals === 'undefined' ) {
298
+ options . setupExitSignals = true ;
299
+ }
300
+
301
+ if ( typeof options . static === 'undefined' ) {
302
+ options . static = [ defaultOptionsForStatic ] ;
303
+ } else if ( typeof options . static === 'boolean' ) {
304
+ options . static = options . static ? [ defaultOptionsForStatic ] : false ;
305
+ } else if ( typeof options . static === 'string' ) {
306
+ options . static = [
307
+ { ...defaultOptionsForStatic , directory : options . static } ,
308
+ ] ;
309
+ } else if ( Array . isArray ( options . static ) ) {
310
+ options . static = options . static . map ( ( item ) => {
311
+ if ( typeof item === 'string' ) {
312
+ return { ...defaultOptionsForStatic , directory : item } ;
313
+ }
314
+
315
+ return { ...defaultOptionsForStatic , ...item } ;
316
+ } ) ;
317
+ } else {
318
+ options . static = [ { ...defaultOptionsForStatic , ...options . static } ] ;
319
+ }
320
+
321
+ if ( options . static ) {
322
+ const isAbsoluteUrl = require ( 'is-absolute-url' ) ;
323
+
324
+ options . static . forEach ( ( staticOption ) => {
325
+ if ( isAbsoluteUrl ( staticOption . directory ) ) {
326
+ throw new Error ( 'Using a URL as static.directory is not supported' ) ;
327
+ }
328
+
329
+ // ensure that publicPath is an array
330
+ if ( typeof staticOption . publicPath === 'string' ) {
331
+ staticOption . publicPath = [ staticOption . publicPath ] ;
332
+ }
333
+
334
+ // ensure that watch is an object if true
335
+ if ( staticOption . watch === true ) {
336
+ staticOption . watch = defaultOptionsForStatic . watch ;
337
+ }
338
+
339
+ // ensure that serveIndex is an object if true
340
+ if ( staticOption . serveIndex === true ) {
341
+ staticOption . serveIndex = defaultOptionsForStatic . serveIndex ;
342
+ }
343
+ } ) ;
344
+ }
345
+
346
+ const defaultWebSocketServerType = 'ws' ;
347
+ const defaultWebSocketServerOptions = { path : '/ws' } ;
348
+
349
+ if ( typeof options . webSocketServer === 'undefined' ) {
350
+ options . webSocketServer = {
351
+ type : defaultWebSocketServerType ,
352
+ options : defaultWebSocketServerOptions ,
353
+ } ;
354
+ } else if (
355
+ typeof options . webSocketServer === 'string' ||
356
+ typeof options . webSocketServer === 'function'
357
+ ) {
358
+ options . webSocketServer = {
359
+ type : options . webSocketServer ,
360
+ options : defaultWebSocketServerOptions ,
361
+ } ;
362
+ } else {
363
+ options . webSocketServer = {
364
+ type : options . webSocketServer . type || defaultWebSocketServerType ,
365
+ options : {
366
+ ...defaultWebSocketServerOptions ,
367
+ ...options . webSocketServer . options ,
368
+ } ,
369
+ } ;
370
+
371
+ if ( typeof options . webSocketServer . options . port === 'string' ) {
372
+ options . webSocketServer . options . port = Number (
373
+ options . webSocketServer . options . port
374
+ ) ;
375
+ }
376
+ }
376
377
}
377
378
378
379
module . exports = normalizeOptions ;
0 commit comments