diff --git a/lib/Server.js b/lib/Server.js index 93bc098643..41cbe3f654 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -560,42 +560,7 @@ class Server { * @returns {boolean} true when target is `web`, otherwise false */ static isWebTarget(compiler) { - if (compiler.platform && compiler.platform.web) { - return compiler.platform.web; - } - - // TODO improve for the next major version and keep only `webTargets` to fallback for old versions - if ( - compiler.options.externalsPresets && - compiler.options.externalsPresets.web - ) { - return true; - } - - if ( - compiler.options.resolve.conditionNames && - compiler.options.resolve.conditionNames.includes("browser") - ) { - return true; - } - - const webTargets = [ - "web", - "webworker", - "electron-preload", - "electron-renderer", - "nwjs", - "node-webkit", - - undefined, - null, - ]; - - if (Array.isArray(compiler.options.target)) { - return compiler.options.target.some((r) => webTargets.includes(r)); - } - - return webTargets.includes(/** @type {string} */ (compiler.options.target)); + return compiler.platform.web || false; } /** @@ -811,21 +776,7 @@ class Server { // Configuration with `web` preset const compilerWithWebPreset = /** @type {MultiCompiler} */ - (this.compiler).compilers.find( - (config) => - (config.options.externalsPresets && - config.options.externalsPresets.web) || - [ - "web", - "webworker", - "electron-preload", - "electron-renderer", - "node-webkit", - - undefined, - null, - ].includes(/** @type {string} */ (config.options.target)), - ); + (this.compiler).compilers.find((config) => Server.isWebTarget(config)); if (compilerWithWebPreset) { return compilerWithWebPreset.options; diff --git a/migration-v6.md b/migration-v6.md index f5aa4c0bbb..40919f82b9 100644 --- a/migration-v6.md +++ b/migration-v6.md @@ -37,6 +37,10 @@ This document serves as a migration guide for `webpack-dev-server@6.0.0`. }; ``` +- Now, webpack-dev-server adds WebSocket communication only when the `target` is set to a web-compatible environment. Previously, it also injected WebSocket communication if `resolve` contained a `conditionNames` entry with `browser` or if `externalsPresets.web` existed. + +- When retrieving the configuration in a multi-compiler setup, it will look for one that has a target compatible with a web environment. If it doesn’t find one, it will fall back to the first compiler found by webpack. + ## Deprecations - The static methods `internalIP` and `internalIPSync` were removed. Use `findIp` instead. diff --git a/package-lock.json b/package-lock.json index e977186fc8..53d6db2a54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19791,9 +19791,9 @@ } }, "node_modules/qs": { - "version": "6.14.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.1.tgz", - "integrity": "sha512-4EK3+xJl8Ts67nLYNwqw/dsFVnCf+qR7RgXSK9jEEm9unao3njwMDdmsdvoKBKHzxd7tCYz5e5M+SnMjdtXGQQ==", + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.0.tgz", + "integrity": "sha512-mAZTtNCeetKMH+pSjrb76NAM8V9a05I9aBZOHztWy/UqcJdQYNsf59vrRKWnojAT9Y+GbIvoTBC++CPHqpDBhQ==", "license": "BSD-3-Clause", "dependencies": { "side-channel": "^1.1.0"