Skip to content

Commit 091ece8

Browse files
refactor!: remove entry options in favor manual (#3494)
1 parent 3067392 commit 091ece8

21 files changed

+433
-464
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,42 +126,42 @@ 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
--open-app-name <value...> Open specified browser.
142135
--open-app <value...> Open specified browser.
143-
--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
144-
(set it to true to open your default browser). https://webpack.js.org/configuration/dev-server/#devserveropen
136+
--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
145137
--open-target-reset Clear all items provided in 'open.target' configuration. Opens specified page in browser.
146138
--open-app-name-reset Clear all items provided in 'open.app.name' configuration. Open specified browser.
147139
--port <value> Allows to specify a port to use. https://webpack.js.org/configuration/dev-server/#devserverport
148-
--static [value...] Allows to configure options for serving static files from directory (by default 'public' directory).
149-
https://webpack.js.org/configuration/dev-server/#devserverstatic
140+
--static [value...] Allows to configure options for serving static files from directory (by default 'public' directory). https://webpack.js.org/configuration/dev-server/#devserverstatic
150141
--no-static Negative 'static' option.
151142
--static-directory <value...> Directory for static contents.
152143
--static-public-path <value...> The static files will be available in the browser under this public path.
153144
--static-serve-index Tells dev server to use serveIndex middleware when enabled.
154145
--no-static-serve-index Negative 'static-serve-index' option.
155146
--static-watch Watches for files in static content directory.
156147
--no-static-watch Negative 'static-watch' option.
157-
--static-reset Clear all items provided in 'static' configuration. Allows to configure options for serving static files from directory (by default 'public'
158-
directory). https://webpack.js.org/configuration/dev-server/#devserverstatic
148+
--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
159149
--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.
160150
--watch-files <value...> Allows to configure list of globs/directories/files to watch for file changes. https://webpack.js.org/configuration/dev-server/#devserverwatchfiles
161-
--watch-files-reset Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes.
162-
https://webpack.js.org/configuration/dev-server/#devserverwatchfiles
151+
--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
163152
--web-socket-server <value> Allows to set web socket server and options (by default 'ws'). https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver
164153
165154
Global options:
166155
--color Enable colors on console.
167156
--no-color Disable colors on console.
168157
-v, --version Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
169158
-h, --help [verbose] Display help for commands and options.
159+
160+
To see list of all supported commands and options run 'webpack --help=verbose'.
161+
162+
Webpack documentation: https://webpack.js.org/.
163+
CLI documentation: https://webpack.js.org/api/cli/.
164+
Made with ♥ by the webpack team.
170165
```
171166

172167
_**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
{

client-src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,19 @@ self.addEventListener('beforeunload', () => {
4444

4545
const onSocketMessage = {
4646
hot() {
47+
if (parsedResourceQuery.hot === 'false') {
48+
return;
49+
}
50+
4751
options.hot = true;
4852

4953
log.info('Hot Module Replacement enabled.');
5054
},
5155
liveReload() {
56+
if (parsedResourceQuery['live-reload'] === 'false') {
57+
return;
58+
}
59+
5260
options.liveReload = true;
5361

5462
log.info('Live Reloading enabled.');

client-src/utils/reloadApp.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,20 @@ function reloadApp({ hot, liveReload }, { isUnloading, currentHash }) {
77
return;
88
}
99

10-
if (hot) {
10+
function applyReload(rootWindow, intervalId) {
11+
clearInterval(intervalId);
12+
13+
log.info('App updated. Reloading...');
14+
15+
rootWindow.location.reload();
16+
}
17+
18+
const search = self.location.search.toLowerCase();
19+
const allowToHot = search.indexOf('webpack-dev-server-hot=false') === -1;
20+
const allowToLiveReload =
21+
search.indexOf('webpack-dev-server-live-reload=false') === -1;
22+
23+
if (hot && allowToHot) {
1124
log.info('App hot update...');
1225

1326
const hotEmitter = require('webpack/hot/emitter');
@@ -20,7 +33,7 @@ function reloadApp({ hot, liveReload }, { isUnloading, currentHash }) {
2033
}
2134
}
2235
// allow refreshing the page only if liveReload isn't disabled
23-
else if (liveReload) {
36+
else if (liveReload && allowToLiveReload) {
2437
let rootWindow = self;
2538

2639
// use parent window for reload (in case we're in an iframe with no valid src)
@@ -38,14 +51,6 @@ function reloadApp({ hot, liveReload }, { isUnloading, currentHash }) {
3851
}
3952
});
4053
}
41-
42-
function applyReload(rootWindow, intervalId) {
43-
clearInterval(intervalId);
44-
45-
log.info('App updated. Reloading...');
46-
47-
rootWindow.location.reload();
48-
}
4954
}
5055

5156
module.exports = reloadApp;

lib/Server.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Server {
4545
initialize() {
4646
this.applyDevServerPlugin();
4747

48-
if (this.options.client.progress) {
48+
if (this.options.client && this.options.client.progress) {
4949
this.setupProgressPlugin();
5050
}
5151

@@ -715,15 +715,15 @@ class Server {
715715
this.sendMessage([connection], 'liveReload');
716716
}
717717

718-
if (this.options.client.progress) {
718+
if (this.options.client && this.options.client.progress) {
719719
this.sendMessage(
720720
[connection],
721721
'progress',
722722
this.options.client.progress
723723
);
724724
}
725725

726-
if (this.options.client.overlay) {
726+
if (this.options.client && this.options.client.overlay) {
727727
this.sendMessage([connection], 'overlay', this.options.client.overlay);
728728
}
729729

@@ -1224,7 +1224,10 @@ class Server {
12241224
}
12251225

12261226
// Also allow if `client.webSocketURL.hostname` provided
1227-
if (typeof this.options.client.webSocketURL !== 'undefined') {
1227+
if (
1228+
this.options.client &&
1229+
typeof this.options.client.webSocketURL !== 'undefined'
1230+
) {
12281231
return this.options.client.webSocketURL.hostname === hostname;
12291232
}
12301233

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
{

0 commit comments

Comments
 (0)