Skip to content

Refactor remove entry options in favor manual #3494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 20 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Following options are available with `webpack serve`:
```
Usage: webpack serve|server|s [entries...] [options]

Run the webpack dev server.

Options:
-c, --config <value...> Provide path to a webpack configuration file e.g. ./webpack.config.js.
--config-name <value...> Name of the configuration to use.
Expand All @@ -83,17 +85,12 @@ Options:
--no-target Negative 'target' option.
--watch-options-stdin Stop watching when stdin stream has ended.
--no-watch-options-stdin Do not stop watching when stdin stream has ended.
--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
--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
--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
--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
--bonjour Allows to broadcasts dev server via ZeroConf networking on start. https://webpack.js.org/configuration/dev-server/#devserverbonjour
--no-bonjour Negative 'bonjour' option.
--client-hot-entry Injects a Hot Module Replacement entry.
--no-client-hot-entry Negative 'client-hot-entry' option.
--client-logging <value> Allows to specify options for client script in the browser. https://webpack.js.org/configuration/dev-server/#devserverclient
--client-need-client-entry Inject a client entry.
--no-client-need-client-entry Negative 'client-need-client-entry' option.
--no-client Negative 'client' option.
--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
--client-overlay Enables a full-screen overlay in the browser when there are compiler errors or warnings.
--no-client-overlay Negative 'client-overlay' option.
--client-overlay-errors Enables a full-screen overlay in the browser when there are compiler errors.
Expand All @@ -112,16 +109,14 @@ Options:
--client-web-socket-url-username <value> Tells clients connected to devServer to use the provided username to authenticate.
--compress Enables gzip compression for everything served. https://webpack.js.org/configuration/dev-server/#devservercompress
--no-compress Negative 'compress' option.
--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
--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
--no-history-api-fallback Negative 'history-api-fallback' option.
--host <value> Allows to specify a hostname to use. https://webpack.js.org/configuration/dev-server/#devserverhost
--hot [value] Enables Hot Module Replacement. https://webpack.js.org/configuration/dev-server/#devserverhot
--no-hot Negative 'hot' option.
--http2 Allows to serve over HTTP/2 using SPDY. https://webpack.js.org/configuration/dev-server/#devserverhttp2
--no-http2 Negative 'http2' option.
--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
--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
--no-https Negative 'https' option.
--https-passphrase <value> Passphrase for a pfx file.
--https-request-cert Request for an SSL certificate.
Expand All @@ -131,42 +126,42 @@ Options:
--https-pfx <value> Path to an SSL pfx file.
--https-cert <value> Path to an SSL certificate.
--ipc [value] Listen to a unix socket. https://webpack.js.org/configuration/dev-server/#devserveripc
--live-reload Enables reload/refresh the page(s) when file changes are detected (enabled by default).
https://webpack.js.org/configuration/dev-server/#devserverlivereload
--live-reload Enables reload/refresh the page(s) when file changes are detected (enabled by default). https://webpack.js.org/configuration/dev-server/#devserverlivereload
--no-live-reload Negative 'live-reload' option.
--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
--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
--no-open Negative 'open' option.
--open-target <value...> Opens specified page in browser.
--open-app-name <value...> Open specified browser.
--open-app <value...> Open specified browser.
--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
--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
--open-target-reset Clear all items provided in 'open.target' configuration. Opens specified page in browser.
--open-app-name-reset Clear all items provided in 'open.app.name' configuration. Open specified browser.
--port <value> Allows to specify a port to use. https://webpack.js.org/configuration/dev-server/#devserverport
--static [value...] Allows to configure options for serving static files from directory (by default 'public' directory).
https://webpack.js.org/configuration/dev-server/#devserverstatic
--static [value...] Allows to configure options for serving static files from directory (by default 'public' directory). https://webpack.js.org/configuration/dev-server/#devserverstatic
--no-static Negative 'static' option.
--static-directory <value...> Directory for static contents.
--static-public-path <value...> The static files will be available in the browser under this public path.
--static-serve-index Tells dev server to use serveIndex middleware when enabled.
--no-static-serve-index Negative 'static-serve-index' option.
--static-watch Watches for files in static content directory.
--no-static-watch Negative 'static-watch' option.
--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
--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
--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.
--watch-files <value...> Allows to configure list of globs/directories/files to watch for file changes. https://webpack.js.org/configuration/dev-server/#devserverwatchfiles
--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
--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
--web-socket-server <value> Allows to set web socket server and options (by default 'ws'). https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver

Global options:
--color Enable colors on console.
--no-color Disable colors on console.
-v, --version Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
-h, --help [verbose] Display help for commands and options.

To see list of all supported commands and options run 'webpack --help=verbose'.

Webpack documentation: https://webpack.js.org/.
CLI documentation: https://webpack.js.org/api/cli/.
Made with ♥ by the webpack team.
```

_**Note**: For more information on above options explore this [link](https://webpack.js.org/configuration/dev-server/)._
Expand Down
47 changes: 18 additions & 29 deletions bin/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,35 @@ module.exports = {
simpleType: 'string',
multiple: false,
},
client: {
configs: [
{
description:
'Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient',
multiple: false,
path: 'client',
type: 'enum',
values: [false],
},
],
description:
'Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient',
multiple: false,
simpleType: 'boolean',
},
'client-logging': {
configs: [
{
type: 'enum',
values: ['none', 'error', 'warn', 'info', 'log', 'verbose'],
multiple: false,
description:
'Allows to specify options for client script in the browser. https://webpack.js.org/configuration/dev-server/#devserverclient',
'Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient',
path: 'client.logging',
},
],
description:
'Allows to specify options for client script in the browser. https://webpack.js.org/configuration/dev-server/#devserverclient',
'Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient',
simpleType: 'string',
multiple: false,
},
Expand Down Expand Up @@ -158,33 +174,6 @@ module.exports = {
simpleType: 'boolean',
multiple: false,
},
'client-need-client-entry': {
configs: [
{
type: 'boolean',
multiple: false,
description: 'Inject a client entry.',
path: 'client.needClientEntry',
},
],
description: 'Inject a client entry.',
simpleType: 'boolean',
multiple: false,
},
'client-hot-entry': {
configs: [
{
type: 'boolean',
multiple: false,
description: 'Injects a Hot Module Replacement entry.',
path: 'client.hotEntry',
},
],
description: 'Injects a Hot Module Replacement entry.',
negatedDescription: 'Does not injects a Hot Module Replacement entry.',
simpleType: 'boolean',
multiple: false,
},
'client-web-socket-url': {
configs: [
{
Expand Down
8 changes: 8 additions & 0 deletions client-src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,19 @@ self.addEventListener('beforeunload', () => {

const onSocketMessage = {
hot() {
if (parsedResourceQuery.hot === 'false') {
return;
}

options.hot = true;

log.info('Hot Module Replacement enabled.');
},
liveReload() {
if (parsedResourceQuery['live-reload'] === 'false') {
return;
}

options.liveReload = true;

log.info('Live Reloading enabled.');
Expand Down
25 changes: 15 additions & 10 deletions client-src/utils/reloadApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@ function reloadApp({ hot, liveReload }, { isUnloading, currentHash }) {
return;
}

if (hot) {
function applyReload(rootWindow, intervalId) {
clearInterval(intervalId);

log.info('App updated. Reloading...');

rootWindow.location.reload();
}

const search = self.location.search.toLowerCase();
const allowToHot = search.indexOf('webpack-dev-server-hot=false') === -1;
const allowToLiveReload =
search.indexOf('webpack-dev-server-live-reload=false') === -1;

if (hot && allowToHot) {
log.info('App hot update...');

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

// use parent window for reload (in case we're in an iframe with no valid src)
Expand All @@ -38,14 +51,6 @@ function reloadApp({ hot, liveReload }, { isUnloading, currentHash }) {
}
});
}

function applyReload(rootWindow, intervalId) {
clearInterval(intervalId);

log.info('App updated. Reloading...');

rootWindow.location.reload();
}
}

module.exports = reloadApp;
11 changes: 7 additions & 4 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Server {
initialize() {
this.applyDevServerPlugin();

if (this.options.client.progress) {
if (this.options.client && this.options.client.progress) {
this.setupProgressPlugin();
}

Expand Down Expand Up @@ -715,15 +715,15 @@ class Server {
this.sendMessage([connection], 'liveReload');
}

if (this.options.client.progress) {
if (this.options.client && this.options.client.progress) {
this.sendMessage(
[connection],
'progress',
this.options.client.progress
);
}

if (this.options.client.overlay) {
if (this.options.client && this.options.client.overlay) {
this.sendMessage([connection], 'overlay', this.options.client.overlay);
}

Expand Down Expand Up @@ -1224,7 +1224,10 @@ class Server {
}

// Also allow if `client.webSocketURL.hostname` provided
if (typeof this.options.client.webSocketURL !== 'undefined') {
if (
this.options.client &&
typeof this.options.client.webSocketURL !== 'undefined'
) {
return this.options.client.webSocketURL.hostname === hostname;
}

Expand Down
63 changes: 21 additions & 42 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,59 +37,38 @@
"description": "Allows to broadcasts dev server via ZeroConf networking on start. https://webpack.js.org/configuration/dev-server/#devserverbonjour"
},
"Client": {
"type": "object",
"description": "Allows to specify options for client script in the browser. https://webpack.js.org/configuration/dev-server/#devserverclient",
"additionalProperties": false,
"properties": {
"hotEntry": {
"$ref": "#/definitions/ClientHotEntry"
},
"logging": {
"$ref": "#/definitions/ClientLogging"
},
"needClientEntry": {
"$ref": "#/definitions/ClientNeedClientEntry"
},
"overlay": {
"$ref": "#/definitions/ClientOverlay"
},
"progress": {
"$ref": "#/definitions/ClientProgress"
},
"transport": {
"$ref": "#/definitions/ClientTransport"
},
"webSocketURL": {
"$ref": "#/definitions/ClientWebSocketURL"
}
}
},
"ClientHotEntry": {
"description": "Injects a Hot Module Replacement entry.",
"description": "Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient",
"anyOf": [
{
"type": "boolean"
"enum": [false]
},
{
"instanceof": "Function"
"type": "object",
"additionalProperties": false,
"properties": {
"logging": {
"$ref": "#/definitions/ClientLogging"
},
"overlay": {
"$ref": "#/definitions/ClientOverlay"
},
"progress": {
"$ref": "#/definitions/ClientProgress"
},
"transport": {
"$ref": "#/definitions/ClientTransport"
},
"webSocketURL": {
"$ref": "#/definitions/ClientWebSocketURL"
}
}
}
]
},
"ClientLogging": {
"enum": ["none", "error", "warn", "info", "log", "verbose"],
"decription": "Allows to set log level in the browser."
},
"ClientNeedClientEntry": {
"description": "Inject a client entry.",
"anyOf": [
{
"type": "boolean"
},
{
"instanceof": "Function"
}
]
},
"ClientOverlay": {
"anyOf": [
{
Expand Down
Loading