Skip to content

Commit 2b7723b

Browse files
refactor: update code and tests
1 parent caa78e6 commit 2b7723b

14 files changed

+135
-406
lines changed

README.md

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Following options are available with `webpack serve`:
6363
```
6464
Usage: webpack serve|server|s [entries...] [options]
6565
66+
Run the webpack dev server.
67+
6668
Options:
6769
-c, --config <value...> Provide path to a webpack configuration file e.g. ./webpack.config.js.
6870
--config-name <value...> Name of the configuration to use.
@@ -83,17 +85,12 @@ Options:
8385
--no-target Negative 'target' option.
8486
--watch-options-stdin Stop watching when stdin stream has ended.
8587
--no-watch-options-stdin Do not stop watching when stdin stream has ended.
86-
--allowed-hosts <value...> 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').
87-
https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
88-
--allowed-hosts-reset Clear all items provided in 'allowedHosts' configuration. Allows to enumerate the hosts from which access to the dev server are allowed (useful
89-
when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
88+
--allowed-hosts <value...> 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
89+
--allowed-hosts-reset 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
9090
--bonjour Allows to broadcasts dev server via ZeroConf networking on start. https://webpack.js.org/configuration/dev-server/#devserverbonjour
9191
--no-bonjour Negative 'bonjour' option.
92-
--client-hot-entry Injects a Hot Module Replacement entry.
93-
--no-client-hot-entry Negative 'client-hot-entry' option.
94-
--client-logging <value> Allows to specify options for client script in the browser. https://webpack.js.org/configuration/dev-server/#devserverclient
95-
--client-need-client-entry Inject a client entry.
96-
--no-client-need-client-entry Negative 'client-need-client-entry' option.
92+
--no-client Negative 'client' option.
93+
--client-logging <value> Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient
9794
--client-overlay Enables a full-screen overlay in the browser when there are compiler errors or warnings.
9895
--no-client-overlay Negative 'client-overlay' option.
9996
--client-overlay-errors Enables a full-screen overlay in the browser when there are compiler errors.
@@ -112,16 +109,14 @@ Options:
112109
--client-web-socket-url-username <value> Tells clients connected to devServer to use the provided username to authenticate.
113110
--compress Enables gzip compression for everything served. https://webpack.js.org/configuration/dev-server/#devservercompress
114111
--no-compress Negative 'compress' option.
115-
--history-api-fallback Allows to proxy requests through a specified index page (by default 'index.html'), useful for Single Page Applications that utilise the HTML5
116-
History API. https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback
112+
--history-api-fallback Allows to proxy requests through a specified index page (by default 'index.html'), useful for Single Page Applications that utilise the HTML5 History API. https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback
117113
--no-history-api-fallback Negative 'history-api-fallback' option.
118114
--host <value> Allows to specify a hostname to use. https://webpack.js.org/configuration/dev-server/#devserverhost
119115
--hot [value] Enables Hot Module Replacement. https://webpack.js.org/configuration/dev-server/#devserverhot
120116
--no-hot Negative 'hot' option.
121117
--http2 Allows to serve over HTTP/2 using SPDY. https://webpack.js.org/configuration/dev-server/#devserverhttp2
122118
--no-http2 Negative 'http2' option.
123-
--https Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).
124-
https://webpack.js.org/configuration/dev-server/#devserverhttps
119+
--https Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). https://webpack.js.org/configuration/dev-server/#devserverhttps
125120
--no-https Negative 'https' option.
126121
--https-passphrase <value> Passphrase for a pfx file.
127122
--https-request-cert Request for an SSL certificate.
@@ -131,43 +126,43 @@ Options:
131126
--https-pfx <value> Path to an SSL pfx file.
132127
--https-cert <value> Path to an SSL certificate.
133128
--ipc [value] Listen to a unix socket. https://webpack.js.org/configuration/dev-server/#devserveripc
134-
--live-reload Enables reload/refresh the page(s) when file changes are detected (enabled by default).
135-
https://webpack.js.org/configuration/dev-server/#devserverlivereload
129+
--live-reload Enables reload/refresh the page(s) when file changes are detected (enabled by default). https://webpack.js.org/configuration/dev-server/#devserverlivereload
136130
--no-live-reload Negative 'live-reload' option.
137-
--open [value...] 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).
138-
https://webpack.js.org/configuration/dev-server/#devserveropen
131+
--open [value...] 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
139132
--no-open Negative 'open' option.
140133
--open-target [value...] Opens specified page in browser.
141134
--no-open-target Negative 'open-target' option.
142135
--open-app-name <value...> Open specified browser.
143136
--open-app <value...> Open specified browser.
144-
--open-reset 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
145-
(set it to true to open your default browser). https://webpack.js.org/configuration/dev-server/#devserveropen
137+
--open-reset 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
146138
--open-target-reset Clear all items provided in 'open.target' configuration. Opens specified page in browser.
147139
--open-app-name-reset Clear all items provided in 'open.app.name' configuration. Open specified browser.
148140
--port <value> Allows to specify a port to use. https://webpack.js.org/configuration/dev-server/#devserverport
149-
--static [value...] Allows to configure options for serving static files from directory (by default 'public' directory).
150-
https://webpack.js.org/configuration/dev-server/#devserverstatic
141+
--static [value...] Allows to configure options for serving static files from directory (by default 'public' directory). https://webpack.js.org/configuration/dev-server/#devserverstatic
151142
--no-static Negative 'static' option.
152143
--static-directory <value...> Directory for static contents.
153144
--static-public-path <value...> The static files will be available in the browser under this public path.
154145
--static-serve-index Tells dev server to use serveIndex middleware when enabled.
155146
--no-static-serve-index Negative 'static-serve-index' option.
156147
--static-watch Watches for files in static content directory.
157148
--no-static-watch Negative 'static-watch' option.
158-
--static-reset Clear all items provided in 'static' configuration. Allows to configure options for serving static files from directory (by default 'public'
159-
directory). https://webpack.js.org/configuration/dev-server/#devserverstatic
149+
--static-reset 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
160150
--static-public-path-reset Clear all items provided in 'static.publicPath' configuration. The static files will be available in the browser under this public path.
161151
--watch-files <value...> Allows to configure list of globs/directories/files to watch for file changes. https://webpack.js.org/configuration/dev-server/#devserverwatchfiles
162-
--watch-files-reset Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes.
163-
https://webpack.js.org/configuration/dev-server/#devserverwatchfiles
152+
--watch-files-reset 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
164153
--web-socket-server <value> Allows to set web socket server and options (by default 'ws'). https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver
165154
166155
Global options:
167156
--color Enable colors on console.
168157
--no-color Disable colors on console.
169158
-v, --version Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
170159
-h, --help [verbose] Display help for commands and options.
160+
161+
To see list of all supported commands and options run 'webpack --help=verbose'.
162+
163+
Webpack documentation: https://webpack.js.org/.
164+
CLI documentation: https://webpack.js.org/api/cli/.
165+
Made with ♥ by the webpack team.
171166
```
172167

173168
_**Note**: For more information on above options explore this [link](https://webpack.js.org/configuration/dev-server/)._

bin/cli-flags.js

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,35 @@ module.exports = {
7979
simpleType: 'string',
8080
multiple: false,
8181
},
82+
client: {
83+
configs: [
84+
{
85+
description:
86+
'Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient',
87+
multiple: false,
88+
path: 'client',
89+
type: 'enum',
90+
values: [false],
91+
},
92+
],
93+
description:
94+
'Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient',
95+
multiple: false,
96+
simpleType: 'boolean',
97+
},
8298
'client-logging': {
8399
configs: [
84100
{
85101
type: 'enum',
86102
values: ['none', 'error', 'warn', 'info', 'log', 'verbose'],
87103
multiple: false,
88104
description:
89-
'Allows to specify options for client script in the browser. https://webpack.js.org/configuration/dev-server/#devserverclient',
105+
'Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient',
90106
path: 'client.logging',
91107
},
92108
],
93109
description:
94-
'Allows to specify options for client script in the browser. https://webpack.js.org/configuration/dev-server/#devserverclient',
110+
'Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient',
95111
simpleType: 'string',
96112
multiple: false,
97113
},
@@ -158,33 +174,6 @@ module.exports = {
158174
simpleType: 'boolean',
159175
multiple: false,
160176
},
161-
'client-need-client-entry': {
162-
configs: [
163-
{
164-
type: 'boolean',
165-
multiple: false,
166-
description: 'Inject a client entry.',
167-
path: 'client.needClientEntry',
168-
},
169-
],
170-
description: 'Inject a client entry.',
171-
simpleType: 'boolean',
172-
multiple: false,
173-
},
174-
'client-hot-entry': {
175-
configs: [
176-
{
177-
type: 'boolean',
178-
multiple: false,
179-
description: 'Injects a Hot Module Replacement entry.',
180-
path: 'client.hotEntry',
181-
},
182-
],
183-
description: 'Injects a Hot Module Replacement entry.',
184-
negatedDescription: 'Does not injects a Hot Module Replacement entry.',
185-
simpleType: 'boolean',
186-
multiple: false,
187-
},
188177
'client-web-socket-url': {
189178
configs: [
190179
{

lib/options.json

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,59 +37,38 @@
3737
"description": "Allows to broadcasts dev server via ZeroConf networking on start. https://webpack.js.org/configuration/dev-server/#devserverbonjour"
3838
},
3939
"Client": {
40-
"type": "object",
41-
"description": "Allows to specify options for client script in the browser. https://webpack.js.org/configuration/dev-server/#devserverclient",
42-
"additionalProperties": false,
43-
"properties": {
44-
"hotEntry": {
45-
"$ref": "#/definitions/ClientHotEntry"
46-
},
47-
"logging": {
48-
"$ref": "#/definitions/ClientLogging"
49-
},
50-
"needClientEntry": {
51-
"$ref": "#/definitions/ClientNeedClientEntry"
52-
},
53-
"overlay": {
54-
"$ref": "#/definitions/ClientOverlay"
55-
},
56-
"progress": {
57-
"$ref": "#/definitions/ClientProgress"
58-
},
59-
"transport": {
60-
"$ref": "#/definitions/ClientTransport"
61-
},
62-
"webSocketURL": {
63-
"$ref": "#/definitions/ClientWebSocketURL"
64-
}
65-
}
66-
},
67-
"ClientHotEntry": {
68-
"description": "Injects a Hot Module Replacement entry.",
40+
"description": "Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient",
6941
"anyOf": [
7042
{
71-
"type": "boolean"
43+
"enum": [false]
7244
},
7345
{
74-
"instanceof": "Function"
46+
"type": "object",
47+
"additionalProperties": false,
48+
"properties": {
49+
"logging": {
50+
"$ref": "#/definitions/ClientLogging"
51+
},
52+
"overlay": {
53+
"$ref": "#/definitions/ClientOverlay"
54+
},
55+
"progress": {
56+
"$ref": "#/definitions/ClientProgress"
57+
},
58+
"transport": {
59+
"$ref": "#/definitions/ClientTransport"
60+
},
61+
"webSocketURL": {
62+
"$ref": "#/definitions/ClientWebSocketURL"
63+
}
64+
}
7565
}
7666
]
7767
},
7868
"ClientLogging": {
7969
"enum": ["none", "error", "warn", "info", "log", "verbose"],
8070
"decription": "Allows to set log level in the browser."
8171
},
82-
"ClientNeedClientEntry": {
83-
"description": "Inject a client entry.",
84-
"anyOf": [
85-
{
86-
"type": "boolean"
87-
},
88-
{
89-
"instanceof": "Function"
90-
}
91-
]
92-
},
9372
"ClientOverlay": {
9473
"anyOf": [
9574
{

lib/utils/DevServerPlugin.js

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class DevServerPlugin {
191191
getHotEntry() {
192192
const { options } = this;
193193

194-
/** @type {(string[] | string)} */
194+
/** @type {(string[] | string | undefined)} */
195195
let hotEntry;
196196

197197
if (options.hot === 'only') {
@@ -236,51 +236,20 @@ class DevServerPlugin {
236236
* @return {Boolean}
237237
*/
238238

239-
/**
240-
*
241-
* @param {Boolean | checkInjectOptionsParam} option - inject(Hot|Client) it is Boolean | fn => Boolean
242-
* @param {Object} _config
243-
* @param {Boolean} defaultValue
244-
* @return {Boolean}
245-
*/
246-
// eslint-disable-next-line no-shadow
247-
const checkInject = (option, _config, defaultValue) => {
248-
if (typeof option === 'boolean') {
249-
return option;
250-
}
251-
252-
if (typeof option === 'function') {
253-
return option(_config);
254-
}
255-
256-
return defaultValue;
257-
};
258-
259239
const additionalEntries = [];
260240

261241
const clientEntry = this.getClientEntry();
262242

263243
if (
264-
checkInject(
265-
this.options.client ? this.options.client.needClientEntry : null,
266-
compiler.options,
267-
this.isWebTarget(compiler.options) &&
268-
(Boolean(this.options.hot) || this.options.liveReload)
269-
)
244+
this.isWebTarget(compiler.options) &&
245+
(Boolean(this.options.hot) || this.options.liveReload)
270246
) {
271247
additionalEntries.push(clientEntry);
272248
}
273249

274250
const hotEntry = this.getHotEntry();
275251

276-
if (
277-
hotEntry &&
278-
checkInject(
279-
this.options.client ? this.options.client.hotEntry : null,
280-
compiler.options,
281-
Boolean(this.options.hot)
282-
)
283-
) {
252+
if (hotEntry && Boolean(this.options.hot)) {
284253
additionalEntries.push(hotEntry);
285254
}
286255

lib/utils/normalizeOptions.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ function normalizeOptions(compiler, options, logger, cacheDir) {
7171
};
7272
}
7373

74-
// client.hotEntry
75-
if (typeof options.client.hotEntry === 'undefined') {
76-
options.client.hotEntry = options.hot;
77-
}
78-
7974
if (typeof options.compress === 'undefined') {
8075
options.compress = true;
8176
}

0 commit comments

Comments
 (0)