diff --git a/README.md b/README.md index 6fe6635532..de74d70c14 100644 --- a/README.md +++ b/README.md @@ -80,137 +80,127 @@ Usage: webpack serve|server|s [entries...] [options] Run the webpack dev server. Options: - -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. - --config-name Name of the configuration to use. - -m, --merge Merge two or more configurations using 'webpack-merge'. - --env Environment passed to the configuration when it is a function. - --node-env Sets process.env.NODE_ENV to the specified value. - --progress [value] Print compilation progress during build. - -j, --json [value] Prints result as JSON or store it in a file. - --entry The entry point(s) of your application e.g. ./src/main.js. - -o, --output-path Output location of the file generated by webpack e.g. ./dist/. - -t, --target Sets the build target e.g. node. - -d, --devtool Determine source maps to use. - --no-devtool Do not generate source maps. - --mode Defines the mode to pass to webpack. - --name Name of the configuration. Used when loading multiple configurations. - --stats [value] It instructs webpack on how to treat the stats e.g. verbose. - --no-stats Disable stats output. - --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 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'). - --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'). - --bonjour Allows to broadcasts dev server via ZeroConf networking on start. - --no-bonjour Disallows to broadcasts dev server via ZeroConf networking on start. - --no-client Disables client script. - --client-logging Allows to set log level in the browser. - --client-overlay Enables a full-screen overlay in the browser when there are compiler errors or warnings. - --no-client-overlay Disables the full-screen overlay in the browser when there are compiler errors or warnings. - --client-overlay-errors Enables a full-screen overlay in the browser when there are compiler errors. - --no-client-overlay-errors Disables the full-screen overlay in the browser when there are compiler errors. - --client-overlay-warnings Enables a full-screen overlay in the browser when there are compiler warnings. - --no-client-overlay-warnings Disables the full-screen overlay in the browser when there are compiler warnings. - --client-progress Prints compilation progress in percentage in the browser. - --no-client-progress Does not print compilation progress in percentage in the browser. - --client-reconnect [value] Tells dev-server the number of times it should try to reconnect the client. - --no-client-reconnect Tells dev-server to not to try to reconnect the client. - --client-web-socket-transport Allows to set custom web socket transport to communicate with dev server. - --client-web-socket-url Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to). - --client-web-socket-url-hostname Tells clients connected to devServer to use the provided hostname. - --client-web-socket-url-password Tells clients connected to devServer to use the provided password to authenticate. - --client-web-socket-url-pathname Tells clients connected to devServer to use the provided path to connect. - --client-web-socket-url-port Tells clients connected to devServer to use the provided port. - --client-web-socket-url-protocol Tells clients connected to devServer to use the provided protocol. - --client-web-socket-url-username Tells clients connected to devServer to use the provided username to authenticate. - --compress Enables gzip compression for everything served. - --no-compress Disables gzip compression for everything served. - --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. - --no-history-api-fallback Disallows to proxy requests through a specified index page. - --host Allows to specify a hostname to use. - --hot [value] Enables Hot Module Replacement. - --no-hot Disables Hot Module Replacement. - --http2 Allows to serve over HTTP/2 using SPDY. Deprecated, use the `server` option. - --no-http2 Does not serve over HTTP/2 using SPDY. - --https Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). Deprecated, use the `server` option. - --no-https Disallows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). - --https-ca Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. - --https-ca-reset Clear all items provided in 'https.ca' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the - `server.options.ca` option. - --https-cacert Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. - --https-cacert-reset Clear all items provided in 'https.cacert' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the - `server.options.ca` option. - --https-cert Path to an SSL certificate or content of an SSL certificate. Deprecated, use the `server.options.cert` option. - --https-cert-reset Clear all items provided in 'https.cert' configuration. Path to an SSL certificate or content of an SSL certificate. Deprecated, use the - `server.options.cert` option. - --https-crl Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). Deprecated, use the - `server.options.crl` option. - --https-crl-reset Clear all items provided in 'https.crl' configuration. Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs - (Certificate Revocation Lists). Deprecated, use the `server.options.crl` option. - --https-key Path to an SSL key or content of an SSL key. Deprecated, use the `server.options.key` option. - --https-key-reset Clear all items provided in 'https.key' configuration. Path to an SSL key or content of an SSL key. Deprecated, use the `server.options.key` option. - --https-passphrase Passphrase for a pfx file. Deprecated, use the `server.options.passphrase` option. - --https-pfx Path to an SSL pfx file or content of an SSL pfx file. Deprecated, use the `server.options.pfx` option. - --https-pfx-reset Clear all items provided in 'https.pfx' configuration. Path to an SSL pfx file or content of an SSL pfx file. Deprecated, use the - `server.options.pfx` option. - --https-request-cert Request for an SSL certificate. Deprecated, use the `server.options.requestCert` option. - --no-https-request-cert Does not request for an SSL certificate. - --ipc [value] Listen to a unix socket. - --live-reload Enables reload/refresh the page(s) when file changes are detected (enabled by default). - --no-live-reload Disables reload/refresh the page(s) when file changes are detected (enabled by default) - --magic-html Tells dev-server whether to enable magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js'). - --no-magic-html Disables magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js'). - --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). - --no-open Does not open the default browser. - --open-app Open specified browser. Deprecated: please use '--open-app-name'. - --open-app-name Open specified browser. - --open-app-name-reset Clear all items provided in 'open.app.name' configuration. 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). - --open-target Opens specified page in browser. - --open-target-reset Clear all items provided in 'open.target' configuration. Opens specified page in browser. - --port Allows to specify a port to use. - --server-options-ca Path to an SSL CA certificate or content of an SSL CA certificate. - --server-options-ca-reset Clear all items provided in 'server.options.ca' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. - --server-options-cacert Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. - --server-options-cacert-reset Clear all items provided in 'server.options.cacert' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, - use the `server.options.ca` option. - --server-options-cert Path to an SSL certificate or content of an SSL certificate. - --server-options-cert-reset Clear all items provided in 'server.options.cert' configuration. Path to an SSL certificate or content of an SSL certificate. - --server-options-crl Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). - --server-options-crl-reset Clear all items provided in 'server.options.crl' configuration. Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM - formatted CRLs (Certificate Revocation Lists). - --server-options-key Path to an SSL key or content of an SSL key. - --server-options-key-reset Clear all items provided in 'server.options.key' configuration. Path to an SSL key or content of an SSL key. - --server-options-passphrase Passphrase for a pfx file. - --server-options-pfx Path to an SSL pfx file or content of an SSL pfx file. - --server-options-pfx-reset Clear all items provided in 'server.options.pfx' configuration. Path to an SSL pfx file or content of an SSL pfx file. - --server-options-request-cert Request for an SSL certificate. - --no-server-options-request-cert Negative 'server-options-request-cert' option. - --server-type Allows to set server and options (by default 'http'). - --static [value...] Allows to configure options for serving static files from directory (by default 'public' directory). - --no-static Negative 'static' option. - --static-directory Directory for static contents. - --static-public-path The static files will be available in the browser under this public path. - --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. - --static-reset Clear all items provided in 'static' configuration. Allows to configure options for serving static files from directory (by default 'public' - directory). - --static-serve-index Tells dev server to use serveIndex middleware when enabled. - --no-static-serve-index Does not tell dev server to use serveIndex middleware. - --static-watch Watches for files in static content directory. - --no-static-watch Does not watch for files in static content directory. - --watch-files Allows to configure list of globs/directories/files to watch for file changes. - --watch-files-reset Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes. - --web-socket-server Deprecated: please use '--web-socket-server-type' option. Allows to set web socket server and options (by default 'ws'). - --no-web-socket-server Negative 'web-socket-server' option. - --web-socket-server-type Allows to set web socket server and options (by default 'ws'). + -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. + --config-name Name of the configuration to use. + -m, --merge Merge two or more configurations using 'webpack-merge'. + --env Environment passed to the configuration when it is a function. + --node-env Sets process.env.NODE_ENV to the specified value. + --progress [value] Print compilation progress during build. + -j, --json [value] Prints result as JSON or store it in a file. + -d, --devtool Determine source maps to use. + --no-devtool Do not generate source maps. + --entry The entry point(s) of your application e.g. ./src/main.js. + --mode Defines the mode to pass to webpack. + --name Name of the configuration. Used when loading multiple configurations. + -o, --output-path Output location of the file generated by webpack e.g. ./dist/. + --stats [value] It instructs webpack on how to treat the stats e.g. verbose. + --no-stats Disable stats output. + -t, --target Sets the build target e.g. node. + --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 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'). + --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'). + --bonjour Allows to broadcasts dev server via ZeroConf networking on start. + --no-bonjour Disallows to broadcasts dev server via ZeroConf networking on start. + --no-client Disables client script. + --client-logging Allows to set log level in the browser. + --client-overlay Enables a full-screen overlay in the browser when there are compiler errors or warnings. + --no-client-overlay Disables the full-screen overlay in the browser when there are compiler errors or warnings. + --client-overlay-errors Enables a full-screen overlay in the browser when there are compiler errors. + --no-client-overlay-errors Disables the full-screen overlay in the browser when there are compiler errors. + --client-overlay-warnings Enables a full-screen overlay in the browser when there are compiler warnings. + --no-client-overlay-warnings Disables the full-screen overlay in the browser when there are compiler warnings. + --client-overlay-trusted-types-policy-name The name of a Trusted Types policy for the overlay. Defaults to 'webpack-dev-server#overlay'. + --client-progress Prints compilation progress in percentage in the browser. + --no-client-progress Does not print compilation progress in percentage in the browser. + --client-reconnect [value] Tells dev-server the number of times it should try to reconnect the client. + --no-client-reconnect Tells dev-server to not to try to reconnect the client. + --client-web-socket-transport Allows to set custom web socket transport to communicate with dev server. + --client-web-socket-url Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to). + --client-web-socket-url-hostname Tells clients connected to devServer to use the provided hostname. + --client-web-socket-url-pathname Tells clients connected to devServer to use the provided path to connect. + --client-web-socket-url-password Tells clients connected to devServer to use the provided password to authenticate. + --client-web-socket-url-port Tells clients connected to devServer to use the provided port. + --client-web-socket-url-protocol Tells clients connected to devServer to use the provided protocol. + --client-web-socket-url-username Tells clients connected to devServer to use the provided username to authenticate. + --compress Enables gzip compression for everything served. + --no-compress Disables gzip compression for everything served. + --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. + --no-history-api-fallback Disallows to proxy requests through a specified index page. + --host Allows to specify a hostname to use. + --hot [value] Enables Hot Module Replacement. + --no-hot Disables Hot Module Replacement. + --http2 Allows to serve over HTTP/2 using SPDY. Deprecated, use the `server` option. + --no-http2 Does not serve over HTTP/2 using SPDY. + --https Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). Deprecated, use the `server` option. + --no-https Disallows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). + --https-passphrase Passphrase for a pfx file. Deprecated, use the `server.options.passphrase` option. + --https-request-cert Request for an SSL certificate. Deprecated, use the `server.options.requestCert` option. + --no-https-request-cert Does not request for an SSL certificate. + --https-ca Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. + --https-ca-reset Clear all items provided in 'https.ca' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. + --https-cacert Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. + --https-cacert-reset Clear all items provided in 'https.cacert' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. + --https-cert Path to an SSL certificate or content of an SSL certificate. Deprecated, use the `server.options.cert` option. + --https-cert-reset Clear all items provided in 'https.cert' configuration. Path to an SSL certificate or content of an SSL certificate. Deprecated, use the `server.options.cert` option. + --https-crl Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). Deprecated, use the `server.options.crl` option. + --https-crl-reset Clear all items provided in 'https.crl' configuration. Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). Deprecated, use the `server.options.crl` option. + --https-key Path to an SSL key or content of an SSL key. Deprecated, use the `server.options.key` option. + --https-key-reset Clear all items provided in 'https.key' configuration. Path to an SSL key or content of an SSL key. Deprecated, use the `server.options.key` option. + --https-pfx Path to an SSL pfx file or content of an SSL pfx file. Deprecated, use the `server.options.pfx` option. + --https-pfx-reset Clear all items provided in 'https.pfx' configuration. Path to an SSL pfx file or content of an SSL pfx file. Deprecated, use the `server.options.pfx` option. + --ipc [value] Listen to a unix socket. + --live-reload Enables reload/refresh the page(s) when file changes are detected (enabled by default). + --no-live-reload Disables reload/refresh the page(s) when file changes are detected (enabled by default). + --magic-html Tells dev-server whether to enable magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js'). + --no-magic-html Disables magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js'). + --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). + --no-open Does not open the default browser. + --open-target Opens specified page in browser. + --open-app-name Open specified browser. + --open-app Open specified browser. Deprecated: please use '--open-app-name'. + --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). + --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 Allows to specify a port to use. + --server-type Allows to set server and options (by default 'http'). + --server-options-passphrase Passphrase for a pfx file. + --server-options-request-cert Request for an SSL certificate. + --no-server-options-request-cert Does not request for an SSL certificate. + --server-options-ca Path to an SSL CA certificate or content of an SSL CA certificate. + --server-options-ca-reset Clear all items provided in 'server.options.ca' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. + --server-options-cacert Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. + --server-options-cacert-reset Clear all items provided in 'server.options.cacert' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. + --server-options-cert Path to an SSL certificate or content of an SSL certificate. + --server-options-cert-reset Clear all items provided in 'server.options.cert' configuration. Path to an SSL certificate or content of an SSL certificate. + --server-options-crl Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). + --server-options-crl-reset Clear all items provided in 'server.options.crl' configuration. Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). + --server-options-key Path to an SSL key or content of an SSL key. + --server-options-key-reset Clear all items provided in 'server.options.key' configuration. Path to an SSL key or content of an SSL key. + --server-options-pfx Path to an SSL pfx file or content of an SSL pfx file. + --server-options-pfx-reset Clear all items provided in 'server.options.pfx' configuration. Path to an SSL pfx file or content of an SSL pfx file. + --static [value...] Allows to configure options for serving static files from directory (by default 'public' directory). + --no-static Disallows to configure options for serving static files from directory. + --static-directory Directory for static contents. + --static-public-path 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 Does not tell dev server to use serveIndex middleware. + --static-watch Watches for files in static content directory. + --no-static-watch Does not watch for files in static content directory. + --static-reset Clear all items provided in 'static' configuration. Allows to configure options for serving static files from directory (by default 'public' directory). + --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 Allows to configure list of globs/directories/files to watch for file changes. + --watch-files-reset Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes. + --web-socket-server Deprecated: please use '--web-socket-server-type' option. Allows to set web socket server and options (by default 'ws'). + --no-web-socket-server Disallows to set web socket server and options. + --web-socket-server-type Allows to set web socket server and options (by default 'ws'). 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. + --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'. diff --git a/bin/cli-flags.js b/bin/cli-flags.js index 1f1376ef75..ab968c5730 100644 --- a/bin/cli-flags.js +++ b/bin/cli-flags.js @@ -121,6 +121,21 @@ module.exports = { simpleType: "boolean", multiple: false, }, + "client-overlay-trusted-types-policy-name": { + configs: [ + { + description: + "The name of a Trusted Types policy for the overlay. Defaults to 'webpack-dev-server#overlay'.", + multiple: false, + path: "client.overlay.trustedTypesPolicyName", + type: "string", + }, + ], + description: + "The name of a Trusted Types policy for the overlay. Defaults to 'webpack-dev-server#overlay'.", + multiple: false, + simpleType: "string", + }, "client-overlay-warnings": { configs: [ { diff --git a/client-src/index.js b/client-src/index.js index 6f361db83b..e1cdc0b36e 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -15,7 +15,7 @@ import createSocketURL from "./utils/createSocketURL.js"; * @property {boolean} hot * @property {boolean} liveReload * @property {boolean} progress - * @property {boolean | { warnings?: boolean, errors?: boolean }} overlay + * @property {boolean | { warnings?: boolean, errors?: boolean, trustedTypesPolicyName?: string }} overlay * @property {string} [logging] * @property {number} [reconnect] */ @@ -230,7 +230,10 @@ const onSocketMessage = { : options.overlay && options.overlay.warnings; if (needShowOverlayForWarnings) { - show("warning", warnings); + const trustedTypesPolicyName = + typeof options.overlay === "object" && + options.overlay.trustedTypesPolicyName; + show("warning", warnings, trustedTypesPolicyName || null); } if (params && params.preventReloading) { @@ -263,7 +266,10 @@ const onSocketMessage = { : options.overlay && options.overlay.errors; if (needShowOverlayForErrors) { - show("error", errors); + const trustedTypesPolicyName = + typeof options.overlay === "object" && + options.overlay.trustedTypesPolicyName; + show("error", errors, trustedTypesPolicyName || null); } }, /** diff --git a/client-src/overlay.js b/client-src/overlay.js index 5c074702ff..9c92e88b67 100644 --- a/client-src/overlay.js +++ b/client-src/overlay.js @@ -23,10 +23,25 @@ let iframeContainerElement; let containerElement; /** @type {Array<(element: HTMLDivElement) => void>} */ let onLoadQueue = []; +/** @type {TrustedTypePolicy | undefined} */ +let overlayTrustedTypesPolicy; ansiHTML.setColors(colors); -function createContainer() { +/** + * @param {string | null} trustedTypesPolicyName + */ +function createContainer(trustedTypesPolicyName) { + // Enable Trusted Types if they are available in the current browser. + if (window.trustedTypes) { + overlayTrustedTypesPolicy = window.trustedTypes.createPolicy( + trustedTypesPolicyName || "webpack-dev-server#overlay", + { + createHTML: (value) => value, + } + ); + } + iframeContainerElement = document.createElement("iframe"); iframeContainerElement.id = "webpack-dev-server-client-overlay"; iframeContainerElement.src = "about:blank"; @@ -109,8 +124,9 @@ function createContainer() { /** * @param {(element: HTMLDivElement) => void} callback + * @param {string | null} trustedTypesPolicyName */ -function ensureOverlayExists(callback) { +function ensureOverlayExists(callback, trustedTypesPolicyName) { if (containerElement) { // Everything is ready, call the callback right away. callback(containerElement); @@ -124,7 +140,7 @@ function ensureOverlayExists(callback) { return; } - createContainer(); + createContainer(trustedTypesPolicyName); } // Successful compilation. @@ -178,8 +194,9 @@ function formatProblem(type, item) { /** * @param {string} type * @param {Array} messages + * @param {string | null} trustedTypesPolicyName */ -function show(type, messages) { +function show(type, messages, trustedTypesPolicyName) { ensureOverlayExists(() => { messages.forEach((message) => { const entryElement = document.createElement("div"); @@ -193,7 +210,9 @@ function show(type, messages) { const text = ansiHTML(encode(body)); const messageTextNode = document.createElement("div"); - messageTextNode.innerHTML = text; + messageTextNode.innerHTML = overlayTrustedTypesPolicy + ? overlayTrustedTypesPolicy.createHTML(text) + : text; entryElement.appendChild(typeElement); entryElement.appendChild(document.createElement("br")); @@ -205,7 +224,7 @@ function show(type, messages) { /** @type {HTMLDivElement} */ (containerElement).appendChild(entryElement); }); - }); + }, trustedTypesPolicyName); } export { formatProblem, show, hide }; diff --git a/examples/client/trusted-types-overlay/README.md b/examples/client/trusted-types-overlay/README.md new file mode 100644 index 0000000000..4c2e4b7f5e --- /dev/null +++ b/examples/client/trusted-types-overlay/README.md @@ -0,0 +1,36 @@ +# client.overlay.trustedTypesPolicyName option + +**webpack.config.js** + +```js +module.exports = { + // ... + output: { + trustedTypes: { policyName: "webpack" }, + }, + devServer: { + client: { + overlay: { + trustedTypesPolicyName: "webpack#dev-overlay", + }, + }, + }, +}; +``` + +Usage via CLI: + +```shell +npx webpack serve --open +``` + +## What Should Happen + +1. The script should open `http://localhost:8080/` in your default browser. +2. You should see an overlay in browser for compilation errors. +3. Modify `devServer.client.overlay.trustedTypesPolicyName` in webpack.config.js to `disallowed-policy` and save. +4. Restart the command and you should not see an overlay at all. In the console you should see the following error: + +``` +Refused to create a TrustedTypePolicy named 'disallowed-policy' because it violates the following Content Security Policy directive: "trusted-types webpack webpack#dev-overlay". +``` diff --git a/examples/client/trusted-types-overlay/app.js b/examples/client/trusted-types-overlay/app.js new file mode 100644 index 0000000000..0c5dbd0635 --- /dev/null +++ b/examples/client/trusted-types-overlay/app.js @@ -0,0 +1,6 @@ +"use strict"; + +const target = document.querySelector("#target"); + +target.classList.add("pass"); +target.textContent = "Success!"; diff --git a/examples/client/trusted-types-overlay/layout.html b/examples/client/trusted-types-overlay/layout.html new file mode 100644 index 0000000000..b71ee9a7cf --- /dev/null +++ b/examples/client/trusted-types-overlay/layout.html @@ -0,0 +1,38 @@ + + + + + + + + WDS ▻ <%= htmlWebpackPlugin.options.title %> + + + + + + + +
+
+

+ + webpack-dev-server +

+
+
+

<%= htmlWebpackPlugin.options.title %>

+
+
+
+ + diff --git a/examples/client/trusted-types-overlay/webpack.config.js b/examples/client/trusted-types-overlay/webpack.config.js new file mode 100644 index 0000000000..3009abed0c --- /dev/null +++ b/examples/client/trusted-types-overlay/webpack.config.js @@ -0,0 +1,32 @@ +"use strict"; + +const path = require("path"); +const HtmlWebpackPlugin = require("html-webpack-plugin"); +// our setup function adds behind-the-scenes bits to the config that all of our +// examples need +const { setup } = require("../../util"); + +const config = setup({ + context: __dirname, + // create error for overlay + entry: "./invalid.js", + output: { + trustedTypes: { policyName: "webpack" }, + }, + devServer: { + client: { + overlay: { + trustedTypesPolicyName: "webpack#dev-overlay", + }, + }, + }, +}); + +// overwrite the index.html with our own to enable Trusted Types +config.plugins[0] = new HtmlWebpackPlugin({ + filename: "index.html", + template: path.join(__dirname, "./layout.html"), + title: "trusted types overlay", +}); + +module.exports = config; diff --git a/lib/options.json b/lib/options.json index 32b1c84ca1..ad49a930d7 100644 --- a/lib/options.json +++ b/lib/options.json @@ -110,6 +110,10 @@ "cli": { "negatedDescription": "Disables the full-screen overlay in the browser when there are compiler warnings." } + }, + "trustedTypesPolicyName": { + "description": "The name of a Trusted Types policy for the overlay. Defaults to 'webpack-dev-server#overlay'.", + "type": "string" } } } diff --git a/package-lock.json b/package-lock.json index 9d8994090c..75260f4641 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,6 +55,7 @@ "@types/default-gateway": "^3.0.1", "@types/rimraf": "^3.0.2", "@types/sockjs-client": "^1.5.1", + "@types/trusted-types": "^2.0.2", "acorn": "^8.2.4", "babel-jest": "^27.5.1", "babel-loader": "^8.2.4", @@ -3542,6 +3543,12 @@ "integrity": "sha512-ipixuVrh2OdNmauvtT51o3d8z12p6LtFW9in7U79der/kwejjdNchQC5UMn5u/KxNoM7VHHOs/l8KS8uHxhODQ==", "dev": true }, + "node_modules/@types/trusted-types": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.2.tgz", + "integrity": "sha512-F5DIZ36YVLE+PN+Zwws4kJogq47hNgX3Nx6WyDJ3kcplxyke3XIzB8uK5n/Lpm1HBsbGzd6nmGehL8cPekP+Tg==", + "dev": true + }, "node_modules/@types/uglify-js": { "version": "3.13.1", "resolved": "https://registry.npmjs.org/@types/uglify-js/-/uglify-js-3.13.1.tgz", @@ -18415,6 +18422,12 @@ "integrity": "sha512-ipixuVrh2OdNmauvtT51o3d8z12p6LtFW9in7U79der/kwejjdNchQC5UMn5u/KxNoM7VHHOs/l8KS8uHxhODQ==", "dev": true }, + "@types/trusted-types": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.2.tgz", + "integrity": "sha512-F5DIZ36YVLE+PN+Zwws4kJogq47hNgX3Nx6WyDJ3kcplxyke3XIzB8uK5n/Lpm1HBsbGzd6nmGehL8cPekP+Tg==", + "dev": true + }, "@types/uglify-js": { "version": "3.13.1", "resolved": "https://registry.npmjs.org/@types/uglify-js/-/uglify-js-3.13.1.tgz", diff --git a/package.json b/package.json index b819330d08..5fe485350d 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "@types/default-gateway": "^3.0.1", "@types/rimraf": "^3.0.2", "@types/sockjs-client": "^1.5.1", + "@types/trusted-types": "^2.0.2", "acorn": "^8.2.4", "babel-jest": "^27.5.1", "babel-loader": "^8.2.4", diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack5 b/test/__snapshots__/validate-options.test.js.snap.webpack5 index 200dbbaf63..04f19dc2d9 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack5 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack5 @@ -90,19 +90,19 @@ exports[`options validate should throw an error on the "client" option with '{"o -> Read more at https://webpack.js.org/configuration/dev-server/#devserverclient Details: * options.client.overlay should be one of these: - boolean | object { errors?, warnings? } + boolean | object { errors?, warnings?, trustedTypesPolicyName? } Details: * options.client.overlay should be a boolean. -> Enables a full-screen overlay in the browser when there are compiler errors or warnings. -> Read more at https://webpack.js.org/configuration/dev-server/#overlay * options.client.overlay should be an object: - object { errors?, warnings? }" + object { errors?, warnings?, trustedTypesPolicyName? }" `; exports[`options validate should throw an error on the "client" option with '{"overlay":{"arbitrary":""}}' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.client.overlay has an unknown property 'arbitrary'. These properties are valid: - object { errors?, warnings? }" + object { errors?, warnings?, trustedTypesPolicyName? }" `; exports[`options validate should throw an error on the "client" option with '{"overlay":{"errors":""}}' value 1`] = ` diff --git a/test/cli/__snapshots__/basic.test.js.snap.webpack5 b/test/cli/__snapshots__/basic.test.js.snap.webpack5 index 3649bb9ee5..59c23b8fdf 100644 --- a/test/cli/__snapshots__/basic.test.js.snap.webpack5 +++ b/test/cli/__snapshots__/basic.test.js.snap.webpack5 @@ -36,126 +36,127 @@ exports[`basic should output help should generate correct cli flags 1`] = ` Run the webpack dev server. Options: - -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. - --config-name Name of the configuration to use. - -m, --merge Merge two or more configurations using 'webpack-merge'. - --env Environment passed to the configuration when it is a function. - --node-env Sets process.env.NODE_ENV to the specified value. - --progress [value] Print compilation progress during build. - -j, --json [value] Prints result as JSON or store it in a file. - -d, --devtool Determine source maps to use. - --no-devtool Do not generate source maps. - --entry The entry point(s) of your application e.g. ./src/main.js. - --mode Defines the mode to pass to webpack. - --name Name of the configuration. Used when loading multiple configurations. - -o, --output-path Output location of the file generated by webpack e.g. ./dist/. - --stats [value] It instructs webpack on how to treat the stats e.g. verbose. - --no-stats Disable stats output. - -t, --target Sets the build target e.g. node. - --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 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'). - --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'). - --bonjour Allows to broadcasts dev server via ZeroConf networking on start. - --no-bonjour Disallows to broadcasts dev server via ZeroConf networking on start. - --no-client Disables client script. - --client-logging Allows to set log level in the browser. - --client-overlay Enables a full-screen overlay in the browser when there are compiler errors or warnings. - --no-client-overlay Disables the full-screen overlay in the browser when there are compiler errors or warnings. - --client-overlay-errors Enables a full-screen overlay in the browser when there are compiler errors. - --no-client-overlay-errors Disables the full-screen overlay in the browser when there are compiler errors. - --client-overlay-warnings Enables a full-screen overlay in the browser when there are compiler warnings. - --no-client-overlay-warnings Disables the full-screen overlay in the browser when there are compiler warnings. - --client-progress Prints compilation progress in percentage in the browser. - --no-client-progress Does not print compilation progress in percentage in the browser. - --client-reconnect [value] Tells dev-server the number of times it should try to reconnect the client. - --no-client-reconnect Tells dev-server to not to try to reconnect the client. - --client-web-socket-transport Allows to set custom web socket transport to communicate with dev server. - --client-web-socket-url Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to). - --client-web-socket-url-hostname Tells clients connected to devServer to use the provided hostname. - --client-web-socket-url-pathname Tells clients connected to devServer to use the provided path to connect. - --client-web-socket-url-password Tells clients connected to devServer to use the provided password to authenticate. - --client-web-socket-url-port Tells clients connected to devServer to use the provided port. - --client-web-socket-url-protocol Tells clients connected to devServer to use the provided protocol. - --client-web-socket-url-username Tells clients connected to devServer to use the provided username to authenticate. - --compress Enables gzip compression for everything served. - --no-compress Disables gzip compression for everything served. - --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. - --no-history-api-fallback Disallows to proxy requests through a specified index page. - --host Allows to specify a hostname to use. - --hot [value] Enables Hot Module Replacement. - --no-hot Disables Hot Module Replacement. - --http2 Allows to serve over HTTP/2 using SPDY. Deprecated, use the \`server\` option. - --no-http2 Does not serve over HTTP/2 using SPDY. - --https Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). Deprecated, use the \`server\` option. - --no-https Disallows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). - --https-passphrase Passphrase for a pfx file. Deprecated, use the \`server.options.passphrase\` option. - --https-request-cert Request for an SSL certificate. Deprecated, use the \`server.options.requestCert\` option. - --no-https-request-cert Does not request for an SSL certificate. - --https-ca Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the \`server.options.ca\` option. - --https-ca-reset Clear all items provided in 'https.ca' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the \`server.options.ca\` option. - --https-cacert Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the \`server.options.ca\` option. - --https-cacert-reset Clear all items provided in 'https.cacert' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the \`server.options.ca\` option. - --https-cert Path to an SSL certificate or content of an SSL certificate. Deprecated, use the \`server.options.cert\` option. - --https-cert-reset Clear all items provided in 'https.cert' configuration. Path to an SSL certificate or content of an SSL certificate. Deprecated, use the \`server.options.cert\` option. - --https-crl Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). Deprecated, use the \`server.options.crl\` option. - --https-crl-reset Clear all items provided in 'https.crl' configuration. Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). Deprecated, use the \`server.options.crl\` option. - --https-key Path to an SSL key or content of an SSL key. Deprecated, use the \`server.options.key\` option. - --https-key-reset Clear all items provided in 'https.key' configuration. Path to an SSL key or content of an SSL key. Deprecated, use the \`server.options.key\` option. - --https-pfx Path to an SSL pfx file or content of an SSL pfx file. Deprecated, use the \`server.options.pfx\` option. - --https-pfx-reset Clear all items provided in 'https.pfx' configuration. Path to an SSL pfx file or content of an SSL pfx file. Deprecated, use the \`server.options.pfx\` option. - --ipc [value] Listen to a unix socket. - --live-reload Enables reload/refresh the page(s) when file changes are detected (enabled by default). - --no-live-reload Disables reload/refresh the page(s) when file changes are detected (enabled by default). - --magic-html Tells dev-server whether to enable magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js'). - --no-magic-html Disables magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js'). - --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). - --no-open Does not open the default browser. - --open-target Opens specified page in browser. - --open-app-name Open specified browser. - --open-app Open specified browser. Deprecated: please use '--open-app-name'. - --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). - --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 Allows to specify a port to use. - --server-type Allows to set server and options (by default 'http'). - --server-options-passphrase Passphrase for a pfx file. - --server-options-request-cert Request for an SSL certificate. - --no-server-options-request-cert Does not request for an SSL certificate. - --server-options-ca Path to an SSL CA certificate or content of an SSL CA certificate. - --server-options-ca-reset Clear all items provided in 'server.options.ca' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. - --server-options-cacert Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the \`server.options.ca\` option. - --server-options-cacert-reset Clear all items provided in 'server.options.cacert' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the \`server.options.ca\` option. - --server-options-cert Path to an SSL certificate or content of an SSL certificate. - --server-options-cert-reset Clear all items provided in 'server.options.cert' configuration. Path to an SSL certificate or content of an SSL certificate. - --server-options-crl Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). - --server-options-crl-reset Clear all items provided in 'server.options.crl' configuration. Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). - --server-options-key Path to an SSL key or content of an SSL key. - --server-options-key-reset Clear all items provided in 'server.options.key' configuration. Path to an SSL key or content of an SSL key. - --server-options-pfx Path to an SSL pfx file or content of an SSL pfx file. - --server-options-pfx-reset Clear all items provided in 'server.options.pfx' configuration. Path to an SSL pfx file or content of an SSL pfx file. - --static [value...] Allows to configure options for serving static files from directory (by default 'public' directory). - --no-static Disallows to configure options for serving static files from directory. - --static-directory Directory for static contents. - --static-public-path 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 Does not tell dev server to use serveIndex middleware. - --static-watch Watches for files in static content directory. - --no-static-watch Does not watch for files in static content directory. - --static-reset Clear all items provided in 'static' configuration. Allows to configure options for serving static files from directory (by default 'public' directory). - --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 Allows to configure list of globs/directories/files to watch for file changes. - --watch-files-reset Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes. - --web-socket-server Deprecated: please use '--web-socket-server-type' option. Allows to set web socket server and options (by default 'ws'). - --no-web-socket-server Disallows to set web socket server and options. - --web-socket-server-type Allows to set web socket server and options (by default 'ws'). + -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. + --config-name Name of the configuration to use. + -m, --merge Merge two or more configurations using 'webpack-merge'. + --env Environment passed to the configuration when it is a function. + --node-env Sets process.env.NODE_ENV to the specified value. + --progress [value] Print compilation progress during build. + -j, --json [value] Prints result as JSON or store it in a file. + -d, --devtool Determine source maps to use. + --no-devtool Do not generate source maps. + --entry The entry point(s) of your application e.g. ./src/main.js. + --mode Defines the mode to pass to webpack. + --name Name of the configuration. Used when loading multiple configurations. + -o, --output-path Output location of the file generated by webpack e.g. ./dist/. + --stats [value] It instructs webpack on how to treat the stats e.g. verbose. + --no-stats Disable stats output. + -t, --target Sets the build target e.g. node. + --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 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'). + --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'). + --bonjour Allows to broadcasts dev server via ZeroConf networking on start. + --no-bonjour Disallows to broadcasts dev server via ZeroConf networking on start. + --no-client Disables client script. + --client-logging Allows to set log level in the browser. + --client-overlay Enables a full-screen overlay in the browser when there are compiler errors or warnings. + --no-client-overlay Disables the full-screen overlay in the browser when there are compiler errors or warnings. + --client-overlay-errors Enables a full-screen overlay in the browser when there are compiler errors. + --no-client-overlay-errors Disables the full-screen overlay in the browser when there are compiler errors. + --client-overlay-warnings Enables a full-screen overlay in the browser when there are compiler warnings. + --no-client-overlay-warnings Disables the full-screen overlay in the browser when there are compiler warnings. + --client-overlay-trusted-types-policy-name The name of a Trusted Types policy for the overlay. Defaults to 'webpack-dev-server#overlay'. + --client-progress Prints compilation progress in percentage in the browser. + --no-client-progress Does not print compilation progress in percentage in the browser. + --client-reconnect [value] Tells dev-server the number of times it should try to reconnect the client. + --no-client-reconnect Tells dev-server to not to try to reconnect the client. + --client-web-socket-transport Allows to set custom web socket transport to communicate with dev server. + --client-web-socket-url Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to). + --client-web-socket-url-hostname Tells clients connected to devServer to use the provided hostname. + --client-web-socket-url-pathname Tells clients connected to devServer to use the provided path to connect. + --client-web-socket-url-password Tells clients connected to devServer to use the provided password to authenticate. + --client-web-socket-url-port Tells clients connected to devServer to use the provided port. + --client-web-socket-url-protocol Tells clients connected to devServer to use the provided protocol. + --client-web-socket-url-username Tells clients connected to devServer to use the provided username to authenticate. + --compress Enables gzip compression for everything served. + --no-compress Disables gzip compression for everything served. + --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. + --no-history-api-fallback Disallows to proxy requests through a specified index page. + --host Allows to specify a hostname to use. + --hot [value] Enables Hot Module Replacement. + --no-hot Disables Hot Module Replacement. + --http2 Allows to serve over HTTP/2 using SPDY. Deprecated, use the `server` option. + --no-http2 Does not serve over HTTP/2 using SPDY. + --https Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). Deprecated, use the `server` option. + --no-https Disallows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). + --https-passphrase Passphrase for a pfx file. Deprecated, use the `server.options.passphrase` option. + --https-request-cert Request for an SSL certificate. Deprecated, use the `server.options.requestCert` option. + --no-https-request-cert Does not request for an SSL certificate. + --https-ca Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. + --https-ca-reset Clear all items provided in 'https.ca' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. + --https-cacert Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. + --https-cacert-reset Clear all items provided in 'https.cacert' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. + --https-cert Path to an SSL certificate or content of an SSL certificate. Deprecated, use the `server.options.cert` option. + --https-cert-reset Clear all items provided in 'https.cert' configuration. Path to an SSL certificate or content of an SSL certificate. Deprecated, use the `server.options.cert` option. + --https-crl Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). Deprecated, use the `server.options.crl` option. + --https-crl-reset Clear all items provided in 'https.crl' configuration. Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). Deprecated, use the `server.options.crl` option. + --https-key Path to an SSL key or content of an SSL key. Deprecated, use the `server.options.key` option. + --https-key-reset Clear all items provided in 'https.key' configuration. Path to an SSL key or content of an SSL key. Deprecated, use the `server.options.key` option. + --https-pfx Path to an SSL pfx file or content of an SSL pfx file. Deprecated, use the `server.options.pfx` option. + --https-pfx-reset Clear all items provided in 'https.pfx' configuration. Path to an SSL pfx file or content of an SSL pfx file. Deprecated, use the `server.options.pfx` option. + --ipc [value] Listen to a unix socket. + --live-reload Enables reload/refresh the page(s) when file changes are detected (enabled by default). + --no-live-reload Disables reload/refresh the page(s) when file changes are detected (enabled by default). + --magic-html Tells dev-server whether to enable magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js'). + --no-magic-html Disables magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js'). + --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). + --no-open Does not open the default browser. + --open-target Opens specified page in browser. + --open-app-name Open specified browser. + --open-app Open specified browser. Deprecated: please use '--open-app-name'. + --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). + --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 Allows to specify a port to use. + --server-type Allows to set server and options (by default 'http'). + --server-options-passphrase Passphrase for a pfx file. + --server-options-request-cert Request for an SSL certificate. + --no-server-options-request-cert Does not request for an SSL certificate. + --server-options-ca Path to an SSL CA certificate or content of an SSL CA certificate. + --server-options-ca-reset Clear all items provided in 'server.options.ca' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. + --server-options-cacert Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. + --server-options-cacert-reset Clear all items provided in 'server.options.cacert' configuration. Path to an SSL CA certificate or content of an SSL CA certificate. Deprecated, use the `server.options.ca` option. + --server-options-cert Path to an SSL certificate or content of an SSL certificate. + --server-options-cert-reset Clear all items provided in 'server.options.cert' configuration. Path to an SSL certificate or content of an SSL certificate. + --server-options-crl Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). + --server-options-crl-reset Clear all items provided in 'server.options.crl' configuration. Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists). + --server-options-key Path to an SSL key or content of an SSL key. + --server-options-key-reset Clear all items provided in 'server.options.key' configuration. Path to an SSL key or content of an SSL key. + --server-options-pfx Path to an SSL pfx file or content of an SSL pfx file. + --server-options-pfx-reset Clear all items provided in 'server.options.pfx' configuration. Path to an SSL pfx file or content of an SSL pfx file. + --static [value...] Allows to configure options for serving static files from directory (by default 'public' directory). + --no-static Disallows to configure options for serving static files from directory. + --static-directory Directory for static contents. + --static-public-path 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 Does not tell dev server to use serveIndex middleware. + --static-watch Watches for files in static content directory. + --no-static-watch Does not watch for files in static content directory. + --static-reset Clear all items provided in 'static' configuration. Allows to configure options for serving static files from directory (by default 'public' directory). + --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 Allows to configure list of globs/directories/files to watch for file changes. + --watch-files-reset Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes. + --web-socket-server Deprecated: please use '--web-socket-server-type' option. Allows to set web socket server and options (by default 'ws'). + --no-web-socket-server Disallows to set web socket server and options. + --web-socket-server-type Allows to set web socket server and options (by default 'ws'). 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. + --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'. diff --git a/test/e2e/__snapshots__/overlay.test.js.snap.webpack5 b/test/e2e/__snapshots__/overlay.test.js.snap.webpack5 index c8a56d4012..7c4fdc318b 100644 --- a/test/e2e/__snapshots__/overlay.test.js.snap.webpack5 +++ b/test/e2e/__snapshots__/overlay.test.js.snap.webpack5 @@ -364,6 +364,14 @@ exports[`overlay should not show initially, then show on an error, then show oth " `; +exports[`overlay should not show overlay when Trusted Types are enabled, but policy is not allowed: page html 1`] = ` +" +

webpack-dev-server is running...

+ + +" +`; + exports[`overlay should show a warning after invalidation: overlay html 1`] = ` "
" `; + +exports[`overlay should show overlay when Trusted Types are enabled: overlay html 1`] = ` +" +
+ Compiled with problems:

+
+ ERROR

+
Error from compilation. Can't find 'test' module.
+

+
+
+ +" +`; + +exports[`overlay should show overlay when Trusted Types are enabled: page html 1`] = ` +" +

webpack-dev-server is running...

+ + + + +" +`; diff --git a/test/e2e/overlay.test.js b/test/e2e/overlay.test.js index c9e91865e9..07d60fd7cc 100644 --- a/test/e2e/overlay.test.js +++ b/test/e2e/overlay.test.js @@ -6,6 +6,7 @@ const prettier = require("prettier"); const webpack = require("webpack"); const Server = require("../../lib/Server"); const config = require("../fixtures/overlay-config/webpack.config"); +const trustedTypesConfig = require("../fixtures/overlay-config/trusted-types.webpack.config"); const runBrowser = require("../helpers/run-browser"); const port = require("../ports-map").overlay; @@ -772,6 +773,81 @@ describe("overlay", () => { await server.stop(); }); + it("should show overlay when Trusted Types are enabled", async () => { + const compiler = webpack(trustedTypesConfig); + + new ErrorPlugin().apply(compiler); + + const devServerOptions = { + port, + client: { + overlay: { + trustedTypesPolicyName: "webpack#dev-overlay", + }, + }, + }; + const server = new Server(devServerOptions, compiler); + + await server.start(); + + const { page, browser } = await runBrowser(); + + await page.goto(`http://localhost:${port}/`, { + waitUntil: "networkidle0", + }); + + const pageHtml = await page.evaluate(() => document.body.outerHTML); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); + const overlayFrame = await overlayHandle.contentFrame(); + const overlayHtml = await overlayFrame.evaluate( + () => document.body.outerHTML + ); + + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" + ); + expect(prettier.format(overlayHtml, { parser: "html" })).toMatchSnapshot( + "overlay html" + ); + + await browser.close(); + await server.stop(); + }); + + it("should not show overlay when Trusted Types are enabled, but policy is not allowed", async () => { + const compiler = webpack(trustedTypesConfig); + + new ErrorPlugin().apply(compiler); + + const devServerOptions = { + port, + client: { + overlay: { + trustedTypesPolicyName: "disallowed-policy", + }, + }, + }; + const server = new Server(devServerOptions, compiler); + + await server.start(); + + const { page, browser } = await runBrowser(); + + await page.goto(`http://localhost:${port}/`, { + waitUntil: "networkidle0", + }); + + const pageHtml = await page.evaluate(() => document.body.outerHTML); + const overlayHandle = await page.$("#webpack-dev-server-client-overlay"); + expect(overlayHandle).toBe(null); + expect(prettier.format(pageHtml, { parser: "html" })).toMatchSnapshot( + "page html" + ); + + await browser.close(); + await server.stop(); + }); + it('should show an error when "client.overlay.errors" is "true"', async () => { const compiler = webpack(config); diff --git a/test/fixtures/overlay-config/trusted-types.webpack.config.js b/test/fixtures/overlay-config/trusted-types.webpack.config.js new file mode 100644 index 0000000000..ca53618cfc --- /dev/null +++ b/test/fixtures/overlay-config/trusted-types.webpack.config.js @@ -0,0 +1,28 @@ +"use strict"; + +const webpack = require("webpack"); +const HTMLGeneratorPlugin = require("../../helpers/trusted-types-html-generator-plugin"); + +const isWebpack5 = webpack.version.startsWith("5"); + +module.exports = { + mode: "development", + context: __dirname, + stats: "none", + entry: "./foo.js", + output: { + path: "/", + trustedTypes: { policyName: "webpack" }, + }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, + plugins: [new HTMLGeneratorPlugin()], +}; diff --git a/test/helpers/trusted-types-html-generator-plugin.js b/test/helpers/trusted-types-html-generator-plugin.js new file mode 100644 index 0000000000..69e5866c46 --- /dev/null +++ b/test/helpers/trusted-types-html-generator-plugin.js @@ -0,0 +1,82 @@ +"use strict"; + +const HTMLContentForIndex = ` + + + + + + webpack-dev-server + + +

webpack-dev-server is running...

+ + + +`; + +const HTMLContentForTest = ` + + + + + + test + + +

Created via HTMLGeneratorPlugin

+ + +`; + +module.exports = class HTMLGeneratorPlugin { + // eslint-disable-next-line class-methods-use-this + apply(compiler) { + const pluginName = "html-generator-plugin"; + + compiler.hooks.thisCompilation.tap(pluginName, (compilation) => { + if (compiler.webpack) { + const { RawSource } = compiler.webpack.sources; + + compilation.hooks.processAssets.tap( + { + name: pluginName, + stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, + }, + () => { + const indexSource = new RawSource(HTMLContentForIndex); + const testSource = new RawSource(HTMLContentForTest); + + compilation.emitAsset("index.html", indexSource); + compilation.emitAsset("test.html", testSource); + } + ); + } else { + compilation.hooks.additionalAssets.tap(pluginName, () => { + compilation.emitAsset("index.html", { + source() { + return HTMLContentForIndex; + }, + size() { + return HTMLContentForIndex.length; + }, + }); + compilation.emitAsset("test.html", { + source() { + return HTMLContentForTest; + }, + size() { + return HTMLContentForTest.length; + }, + }); + }); + } + }); + } +}; diff --git a/types/bin/cli-flags.d.ts b/types/bin/cli-flags.d.ts index fa98132496..ac17b73866 100644 --- a/types/bin/cli-flags.d.ts +++ b/types/bin/cli-flags.d.ts @@ -91,6 +91,17 @@ declare const _exports: { simpleType: string; multiple: boolean; }; + "client-overlay-trusted-types-policy-name": { + configs: { + description: string; + multiple: boolean; + path: string; + type: string; + }[]; + description: string; + multiple: boolean; + simpleType: string; + }; "client-overlay-warnings": { configs: { type: string; diff --git a/types/lib/Server.d.ts b/types/lib/Server.d.ts index 82272d80c8..74cb035570 100644 --- a/types/lib/Server.d.ts +++ b/types/lib/Server.d.ts @@ -393,6 +393,17 @@ declare class Server { simpleType: string; multiple: boolean; }; + "client-overlay-trusted-types-policy-name": { + configs: { + description: string; + multiple: boolean; + path: string; + type: string; + }[]; + description: string; + multiple: boolean; + simpleType: string; + }; "client-overlay-warnings": { configs: { type: string; @@ -417,6 +428,60 @@ declare class Server { simpleType: string; multiple: boolean; }; + /** + * @typedef {Object} WebSocketURL + * @property {string} [hostname] + * @property {string} [password] + * @property {string} [pathname] + * @property {number | string} [port] + * @property {string} [protocol] + * @property {string} [username] + */ + /** + * @typedef {Object} ClientConfiguration + * @property {"log" | "info" | "warn" | "error" | "none" | "verbose"} [logging] + * @property {boolean | { warnings?: boolean, errors?: boolean }} [overlay] + * @property {boolean} [progress] + * @property {boolean | number} [reconnect] + * @property {"ws" | "sockjs" | string} [webSocketTransport] + * @property {string | WebSocketURL} [webSocketURL] + */ + /** + * @typedef {Array<{ key: string; value: string }> | Record} Headers + */ + /** + * @typedef {{ name?: string, path?: string, middleware: ExpressRequestHandler | ExpressErrorRequestHandler } | ExpressRequestHandler | ExpressErrorRequestHandler} Middleware + */ + /** + * @typedef {Object} Configuration + * @property {boolean | string} [ipc] + * @property {Host} [host] + * @property {Port} [port] + * @property {boolean | "only"} [hot] + * @property {boolean} [liveReload] + * @property {DevMiddlewareOptions} [devMiddleware] + * @property {boolean} [compress] + * @property {boolean} [magicHtml] + * @property {"auto" | "all" | string | string[]} [allowedHosts] + * @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback] + * @property {boolean} [setupExitSignals] + * @property {boolean | Record | BonjourOptions} [bonjour] + * @property {string | string[] | WatchFiles | Array} [watchFiles] + * @property {boolean | string | Static | Array} [static] + * @property {boolean | ServerOptions} [https] + * @property {boolean} [http2] + * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] + * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] + * @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy] + * @property {boolean | string | Open | Array} [open] + * @property {boolean} [setupExitSignals] + * @property {boolean | ClientConfiguration} [client] + * @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext) => Headers)} [headers] + * @property {(devServer: Server) => void} [onAfterSetupMiddleware] + * @property {(devServer: Server) => void} [onBeforeSetupMiddleware] + * @property {(devServer: Server) => void} [onListening] + * @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares] + */ "client-reconnect": { configs: ( | { @@ -453,36 +518,6 @@ declare class Server { path: string; } )[]; - /** - * @typedef {Object} Configuration - * @property {boolean | string} [ipc] - * @property {Host} [host] - * @property {Port} [port] - * @property {boolean | "only"} [hot] - * @property {boolean} [liveReload] - * @property {DevMiddlewareOptions} [devMiddleware] - * @property {boolean} [compress] - * @property {boolean} [magicHtml] - * @property {"auto" | "all" | string | string[]} [allowedHosts] - * @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback] - * @property {boolean} [setupExitSignals] - * @property {boolean | Record | BonjourOptions} [bonjour] - * @property {string | string[] | WatchFiles | Array} [watchFiles] - * @property {boolean | string | Static | Array} [static] - * @property {boolean | ServerOptions} [https] - * @property {boolean} [http2] - * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] - * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] - * @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy] - * @property {boolean | string | Open | Array} [open] - * @property {boolean} [setupExitSignals] - * @property {boolean | ClientConfiguration} [client] - * @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext) => Headers)} [headers] - * @property {(devServer: Server) => void} [onAfterSetupMiddleware] - * @property {(devServer: Server) => void} [onBeforeSetupMiddleware] - * @property {(devServer: Server) => void} [onListening] - * @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares] - */ description: string; simpleType: string; multiple: boolean; @@ -539,6 +574,9 @@ declare class Server { path: string; }[]; description: string; + /** + * @type {FSWatcher[]} + */ simpleType: string; multiple: boolean; }; @@ -558,20 +596,12 @@ declare class Server { type: string; } )[]; - /** - * @private - * @type {{ name: string | symbol, listener: (...args: any[]) => void}[] }} - */ description: string; multiple: boolean; simpleType: string; }; "client-web-socket-url-username": { configs: { - /** - * @private - * @type {RequestHandler[]} - */ type: string; multiple: boolean; description: string; @@ -581,6 +611,10 @@ declare class Server { simpleType: string; multiple: boolean; }; + /** + * @param {string} URL + * @returns {boolean} + */ compress: { configs: { type: string; @@ -591,6 +625,10 @@ declare class Server { }[]; description: string; simpleType: string; + /** + * @param {string} gateway + * @returns {string | undefined} + */ multiple: boolean; }; "history-api-fallback": { @@ -623,6 +661,10 @@ declare class Server { )[]; description: string; simpleType: string; + /** + * @param {Host} hostname + * @returns {Promise} + */ multiple: boolean; }; hot: { @@ -632,10 +674,6 @@ declare class Server { multiple: boolean; description: string; negatedDescription: string; - /** - * @param {"v4" | "v6"} family - * @returns {string | undefined} - */ path: string; } | { @@ -662,11 +700,6 @@ declare class Server { simpleType: string; multiple: boolean; }; - /** - * @param {Port} port - * @param {string} host - * @returns {Promise} - */ https: { configs: { type: string; @@ -693,6 +726,9 @@ declare class Server { "https-ca-reset": { configs: { description: string; + /** + * @type {string[]} + */ multiple: boolean; path: string; type: string; @@ -717,7 +753,7 @@ declare class Server { description: string; multiple: boolean; path: string; - type: string /** @type {WebSocketURL} */; + type: string; }[]; description: string; multiple: boolean; @@ -731,7 +767,7 @@ declare class Server { path: string; }[]; description: string; - /** @type {ServerConfiguration} */ simpleType: string; + simpleType: string; multiple: boolean; }; "https-cert-reset": { @@ -827,7 +863,7 @@ declare class Server { type: string; multiple: boolean; description: string; - negatedDescription: string; + /** @type {Object} */ negatedDescription: string; path: string; }[]; description: string; @@ -839,12 +875,13 @@ declare class Server { | { type: string; multiple: boolean; + /** @type {any} */ description: string; path: string; } | { type: string; - values: boolean[]; + /** @type {any} */ values: boolean[]; multiple: boolean; description: string; path: string; @@ -894,7 +931,7 @@ declare class Server { path: string; } )[]; - description: string; + /** @type {Compiler} */ description: string; simpleType: string; multiple: boolean; }; @@ -906,10 +943,6 @@ declare class Server { path: string; }[]; description: string; - /** - * @private - * @returns {Promise} - */ simpleType: string; multiple: boolean; }; @@ -954,13 +987,9 @@ declare class Server { path: string; }[]; description: string; - simpleType: string; + /** @type {NormalizedStatic} */ simpleType: string; multiple: boolean; }; - /** - * @param {string | Static | undefined} [optionsForStatic] - * @returns {NormalizedStatic} - */ "open-target-reset": { configs: { type: string; @@ -1127,14 +1156,15 @@ declare class Server { "server-options-pfx-reset": { configs: { description: string; - /** @type {ServerConfiguration} */ multiple: boolean; + multiple: boolean; path: string; type: string; }[]; description: string; multiple: boolean; - simpleType: string; + simpleType: string /** @type {ServerOptions} */; }; + /** @type {ServerOptions} */ "server-options-request-cert": { configs: { description: string; @@ -1153,10 +1183,10 @@ declare class Server { multiple: boolean; path: string; type: string; - /** @type {ServerOptions} */ values: string[]; + values: string[]; }[]; description: string; - /** @type {Array} */ multiple: boolean; + multiple: boolean; simpleType: string; }; static: { @@ -1170,13 +1200,17 @@ declare class Server { | { type: string; multiple: boolean; + /** + * @param {string | Buffer | undefined} item + * @returns {string | Buffer | undefined} + */ description: string; negatedDescription: string; path: string; } )[]; description: string; - /** @type {ServerOptions} */ simpleType: string; + simpleType: string; multiple: boolean; }; "static-directory": { @@ -1186,7 +1220,7 @@ declare class Server { description: string; path: string; }[]; - description: string; + /** @type {any} */ description: string; simpleType: string; multiple: boolean; }; @@ -1288,12 +1322,14 @@ declare class Server { } | { description: string; - /** @type {ServerOptions & { cacert?: ServerOptions["ca"] }} */ multiple: boolean; + multiple: boolean; path: string; type: string; } )[]; + /** @type {ServerOptions & { cacert?: ServerOptions["ca"] }} */ description: string; + /** @type {ServerOptions} */ simpleType: string; multiple: boolean; }; @@ -1301,7 +1337,6 @@ declare class Server { configs: ( | { description: string; - /** @type {ServerOptions & { cacert?: ServerOptions["ca"] }} */ multiple: boolean; path: string; type: string; @@ -1311,12 +1346,12 @@ declare class Server { description: string; multiple: boolean; path: string; - /** @type {ServerOptions} */ type: string; + type: string; } )[]; description: string; simpleType: string; - /** @type {ServerOptions} */ multiple: boolean; + multiple: boolean; }; }; readonly processArguments: ( @@ -1610,6 +1645,10 @@ declare class Server { negatedDescription: string; }; }; + trustedTypesPolicyName: { + description: string; + type: string; + }; }; description?: undefined; link?: undefined; @@ -1628,21 +1667,103 @@ declare class Server { ClientReconnect: { description: string; link: string; - /** - * @callback ByPass - * @param {Request} req - * @param {Response} res - * @param {ProxyConfigArrayItem} proxyConfig - */ - /** - * @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & { bypass?: ByPass } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem - */ - /** - * @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray - */ - /** - * @typedef {{ [url: string]: string | ProxyConfigArrayItem }} ProxyConfigMap - */ + anyOf: ( + | { + /** + * @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & { bypass?: ByPass } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem + */ + /** + * @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray + */ + /** + * @typedef {{ [url: string]: string | ProxyConfigArrayItem }} ProxyConfigMap + */ + /** + * @typedef {Object} OpenApp + * @property {string} [name] + * @property {string[]} [arguments] + */ + /** + * @typedef {Object} Open + * @property {string | string[] | OpenApp} [app] + * @property {string | string[]} [target] + */ + /** + * @typedef {Object} NormalizedOpen + * @property {string} target + * @property {import("open").Options} options + */ + /** + * @typedef {Object} WebSocketURL + * @property {string} [hostname] + * @property {string} [password] + * @property {string} [pathname] + * @property {number | string} [port] + * @property {string} [protocol] + * @property {string} [username] + */ + /** + * @typedef {Object} ClientConfiguration + * @property {"log" | "info" | "warn" | "error" | "none" | "verbose"} [logging] + * @property {boolean | { warnings?: boolean, errors?: boolean }} [overlay] + * @property {boolean} [progress] + * @property {boolean | number} [reconnect] + * @property {"ws" | "sockjs" | string} [webSocketTransport] + * @property {string | WebSocketURL} [webSocketURL] + */ + /** + * @typedef {Array<{ key: string; value: string }> | Record} Headers + */ + /** + * @typedef {{ name?: string, path?: string, middleware: ExpressRequestHandler | ExpressErrorRequestHandler } | ExpressRequestHandler | ExpressErrorRequestHandler} Middleware + */ + /** + * @typedef {Object} Configuration + * @property {boolean | string} [ipc] + * @property {Host} [host] + * @property {Port} [port] + * @property {boolean | "only"} [hot] + * @property {boolean} [liveReload] + * @property {DevMiddlewareOptions} [devMiddleware] + * @property {boolean} [compress] + * @property {boolean} [magicHtml] + * @property {"auto" | "all" | string | string[]} [allowedHosts] + * @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback] + * @property {boolean} [setupExitSignals] + * @property {boolean | Record | BonjourOptions} [bonjour] + * @property {string | string[] | WatchFiles | Array} [watchFiles] + * @property {boolean | string | Static | Array} [static] + * @property {boolean | ServerOptions} [https] + * @property {boolean} [http2] + * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] + * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] + * @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy] + * @property {boolean | string | Open | Array} [open] + * @property {boolean} [setupExitSignals] + * @property {boolean | ClientConfiguration} [client] + * @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext) => Headers)} [headers] + * @property {(devServer: Server) => void} [onAfterSetupMiddleware] + * @property {(devServer: Server) => void} [onBeforeSetupMiddleware] + * @property {(devServer: Server) => void} [onListening] + * @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares] + */ + type: string; + cli: { + negatedDescription: string; + }; + minimum?: undefined; + } + | { + type: string; + minimum: number; + cli?: undefined /** @typedef {import("express").Request} Request */; + } + )[]; + }; + ClientWebSocketTransport: { + anyOf: { + $ref: string; + }[]; /** * @typedef {Object} OpenApp * @property {string} [name] @@ -1712,25 +1833,6 @@ declare class Server { * @property {(devServer: Server) => void} [onListening] * @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares] */ - anyOf: ( - | { - type: string; - cli: { - negatedDescription: string; - }; - minimum?: undefined; - } - | { - type: string; - minimum: number; - cli?: undefined /** @typedef {import("express").Request} Request */; - } - )[]; - }; - ClientWebSocketTransport: { - anyOf: { - $ref: string; - }[]; description: string; link: string; }; @@ -1740,6 +1842,15 @@ declare class Server { ClientWebSocketTransportString: { type: string; minLength: number; + /** + * @typedef {Object} WebSocketURL + * @property {string} [hostname] + * @property {string} [password] + * @property {string} [pathname] + * @property {number | string} [port] + * @property {string} [protocol] + * @property {string} [username] + */ }; ClientWebSocketURL: { description: string; @@ -1764,9 +1875,6 @@ declare class Server { description: string; type: string; }; - /** - * @typedef {Array<{ key: string; value: string }> | Record} Headers - */ password: { description: string; type: string; @@ -1880,10 +1988,6 @@ declare class Server { } | { instanceof: string; - /** - * @private - * @type {RequestHandler[]} - */ type?: undefined; items?: undefined; } @@ -1953,6 +2057,10 @@ declare class Server { description: string; }; crl: { + /** + * @param {"v4" | "v6"} family + * @returns {Promise} + */ anyOf: ( | { type: string; @@ -2043,9 +2151,6 @@ declare class Server { instanceof?: undefined; } )[]; - /** - * @returns {string} - */ }; instanceof?: undefined; } @@ -2086,9 +2191,6 @@ declare class Server { exclude: boolean; }; }; - /** - * @type {string[]} - */ Headers: { anyOf: ( | { @@ -2113,7 +2215,7 @@ declare class Server { } )[]; description: string; - link: string; + link: string /** @type {WebSocketURL} */; }; HistoryApiFallback: { anyOf: ( @@ -2127,8 +2229,9 @@ declare class Server { } | { type: string; - /** @type {ClientConfiguration} */ description: string; + description: string; link: string; + /** @type {string} */ cli?: undefined /** @typedef {import("express").Request} Request */; } )[]; @@ -2167,7 +2270,7 @@ declare class Server { } )[]; description: string; - /** @type {string} */ link: string; + link: string; }; IPC: { anyOf: ( @@ -2271,6 +2374,12 @@ declare class Server { anyOf: ( | { type: string; + /** + * prependEntry Method for webpack 4 + * @param {any} originalEntry + * @param {any} newAdditionalEntries + * @returns {any} + */ items: { type: string; minLength: number; @@ -2312,6 +2421,7 @@ declare class Server { }; }; }; + /** @type {any} */ OpenString: { type: string; minLength: number; @@ -2326,7 +2436,6 @@ declare class Server { enum?: undefined; } | { - /** @type {any} */ type: string; minLength: number; minimum?: undefined; @@ -2371,7 +2480,7 @@ declare class Server { }; Server: { anyOf: { - $ref: string; + $ref: string /** @type {MultiCompiler} */; }[]; link: string; description: string; @@ -2382,7 +2491,7 @@ declare class Server { ServerEnum: { enum: string[]; cli: { - exclude: boolean /** @type {MultiCompiler} */; + exclude: boolean; }; }; ServerString: { @@ -2522,6 +2631,7 @@ declare class Server { anyOf: ( | { type: string; + /** @type {NormalizedStatic} */ instanceof?: undefined; } | { @@ -2782,7 +2892,7 @@ declare class Server { | { type: string; minLength: number; - /** @type {ServerConfiguration} */ items?: undefined; + items?: undefined; } )[]; description: string; @@ -2804,7 +2914,7 @@ declare class Server { anyOf: { $ref: string; }[]; - /** @type {ServerOptions} */ description: string; + description: string; link: string; }; WebSocketServerType: { @@ -2826,7 +2936,7 @@ declare class Server { } )[]; cli: { - description: string; + description: string /** @type {any} */; }; }; WebSocketServerFunction: {