Skip to content

Commit 5a2216f

Browse files
Merge branch 'master' into issue-3351
2 parents 5afad3e + 23574b7 commit 5a2216f

File tree

6 files changed

+209
-208
lines changed

6 files changed

+209
-208
lines changed

bin/cli-flags.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ module.exports = {
3030
type: 'reset',
3131
multiple: false,
3232
description:
33-
"Clear all items provided in configuration. Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts",
33+
"Clear all items provided in 'allowedHosts' configuration. Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts",
3434
path: 'allowedHosts',
3535
},
3636
],
3737
description:
38-
"Clear all items provided in configuration. Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts",
38+
"Clear all items provided in 'allowedHosts' configuration. Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts",
3939
simpleType: 'boolean',
4040
multiple: false,
4141
},
@@ -614,12 +614,12 @@ module.exports = {
614614
type: 'reset',
615615
multiple: false,
616616
description:
617-
'Clear all items provided in configuration. Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser). https://webpack.js.org/configuration/dev-server/#devserveropen',
617+
"Clear all items provided in 'open' configuration. Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser). https://webpack.js.org/configuration/dev-server/#devserveropen",
618618
path: 'open',
619619
},
620620
],
621621
description:
622-
'Clear all items provided in configuration. Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser). https://webpack.js.org/configuration/dev-server/#devserveropen',
622+
"Clear all items provided in 'open' configuration. Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser). https://webpack.js.org/configuration/dev-server/#devserveropen",
623623
simpleType: 'boolean',
624624
multiple: false,
625625
},
@@ -629,12 +629,12 @@ module.exports = {
629629
type: 'reset',
630630
multiple: false,
631631
description:
632-
'Clear all items provided in configuration. Opens specified page in browser.',
632+
"Clear all items provided in 'open.target' configuration. Opens specified page in browser.",
633633
path: 'open.target',
634634
},
635635
],
636636
description:
637-
'Clear all items provided in configuration. Opens specified page in browser.',
637+
"Clear all items provided in 'open.target' configuration. Opens specified page in browser.",
638638
simpleType: 'boolean',
639639
multiple: false,
640640
},
@@ -644,12 +644,12 @@ module.exports = {
644644
type: 'reset',
645645
multiple: false,
646646
description:
647-
'Clear all items provided in configuration. Open specified browser.',
647+
"Clear all items provided in 'open.app.name' configuration. Open specified browser.",
648648
path: 'open.app.name',
649649
},
650650
],
651651
description:
652-
'Clear all items provided in configuration. Open specified browser.',
652+
"Clear all items provided in 'open.app.name' configuration. Open specified browser.",
653653
simpleType: 'boolean',
654654
multiple: false,
655655
},
@@ -776,12 +776,12 @@ module.exports = {
776776
type: 'reset',
777777
multiple: false,
778778
description:
779-
"Clear all items provided in configuration. Allows to configure options for serving static files from directory (by default 'public' directory). https://webpack.js.org/configuration/dev-server/#devserverstatic",
779+
"Clear all items provided in 'static' configuration. Allows to configure options for serving static files from directory (by default 'public' directory). https://webpack.js.org/configuration/dev-server/#devserverstatic",
780780
path: 'static',
781781
},
782782
],
783783
description:
784-
"Clear all items provided in configuration. Allows to configure options for serving static files from directory (by default 'public' directory). https://webpack.js.org/configuration/dev-server/#devserverstatic",
784+
"Clear all items provided in 'static' configuration. Allows to configure options for serving static files from directory (by default 'public' directory). https://webpack.js.org/configuration/dev-server/#devserverstatic",
785785
simpleType: 'boolean',
786786
multiple: false,
787787
},
@@ -791,12 +791,12 @@ module.exports = {
791791
type: 'reset',
792792
multiple: false,
793793
description:
794-
'Clear all items provided in configuration. The static files will be available in the browser under this public path.',
794+
"Clear all items provided in 'static.publicPath' configuration. The static files will be available in the browser under this public path.",
795795
path: 'static.publicPath',
796796
},
797797
],
798798
description:
799-
'Clear all items provided in configuration. The static files will be available in the browser under this public path.',
799+
"Clear all items provided in 'static.publicPath' configuration. The static files will be available in the browser under this public path.",
800800
simpleType: 'boolean',
801801
multiple: false,
802802
},
@@ -821,12 +821,12 @@ module.exports = {
821821
type: 'reset',
822822
multiple: false,
823823
description:
824-
'Clear all items provided in configuration. Allows to configure list of globs/directories/files to watch for file changes. https://webpack.js.org/configuration/dev-server/#devserverwatchfiles',
824+
"Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes. https://webpack.js.org/configuration/dev-server/#devserverwatchfiles",
825825
path: 'watchFiles',
826826
},
827827
],
828828
description:
829-
'Clear all items provided in configuration. Allows to configure list of globs/directories/files to watch for file changes. https://webpack.js.org/configuration/dev-server/#devserverwatchfiles',
829+
"Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes. https://webpack.js.org/configuration/dev-server/#devserverwatchfiles",
830830
simpleType: 'boolean',
831831
multiple: false,
832832
},

lib/utils/normalizeOptions.js

Lines changed: 105 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -25,92 +25,18 @@ function normalizeOptions(compiler, options, logger, cacheDir) {
2525
watch: watchOptions,
2626
};
2727

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';
8232
}
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'
9537
) {
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];
11440
}
11541

11642
if (!options.client) {
@@ -150,30 +76,17 @@ function normalizeOptions(compiler, options, logger, cacheDir) {
15076
options.client.hotEntry = options.hot;
15177
}
15278

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-
17379
if (typeof options.compress === 'undefined') {
17480
options.compress = true;
17581
}
17682

83+
options.devMiddleware = options.devMiddleware || {};
84+
85+
options.hot =
86+
typeof options.hot === 'boolean' || options.hot === 'only'
87+
? options.hot
88+
: true;
89+
17790
// if the user enables http2, we can safely enable https
17891
if ((options.http2 && !options.https) || options.https === true) {
17992
options.https = {
@@ -306,6 +219,13 @@ function normalizeOptions(compiler, options, logger, cacheDir) {
306219
options.https.cert = options.https.cert || fakeCert;
307220
}
308221

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+
309229
/**
310230
* Assume a proxy configuration specified as:
311231
* proxy: {
@@ -373,6 +293,87 @@ function normalizeOptions(compiler, options, logger, cacheDir) {
373293
}
374294
}
375295
}
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+
}
376377
}
377378

378379
module.exports = normalizeOptions;

0 commit comments

Comments
 (0)