From bb72f1610c36b08930be5a10e65258984ef2370b Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Mon, 16 Feb 2026 02:08:22 +0000 Subject: [PATCH 1/4] feat: use compiler.platform to determine the target --- lib/Server.js | 54 ++++++------------------------------------------- migration-v6.md | 4 ++++ 2 files changed, 10 insertions(+), 48 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 93bc098643..8fcf3a2c0c 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -560,42 +560,9 @@ 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 || compiler.options.externalsPresets?.web || false + ); } /** @@ -813,18 +780,9 @@ class Server { /** @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)), + config.options.externalsPresets?.web || + config.platform?.web || + false, ); if (compilerWithWebPreset) { diff --git a/migration-v6.md b/migration-v6.md index f5aa4c0bbb..c79377688d 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 or when `externalsPresets` includes `web`. + +Previously, it also injected WebSocket communication if `resolve` contained a `conditionNames` entry with `browser`. + ## Deprecations - The static methods `internalIP` and `internalIPSync` were removed. Use `findIp` instead. From a35a9295d70d5d2513679e265f97b8049d96084f Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Mon, 16 Feb 2026 13:44:38 +0000 Subject: [PATCH 2/4] feat: update WebSocket communication conditions and multi-compiler fallback logic --- lib/Server.js | 11 ++--------- migration-v6.md | 4 ++-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 8fcf3a2c0c..41f979e440 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -560,9 +560,7 @@ class Server { * @returns {boolean} true when target is `web`, otherwise false */ static isWebTarget(compiler) { - return ( - compiler.platform?.web || compiler.options.externalsPresets?.web || false - ); + return compiler.platform?.web || false; } /** @@ -778,12 +776,7 @@ class Server { // Configuration with `web` preset const compilerWithWebPreset = /** @type {MultiCompiler} */ - (this.compiler).compilers.find( - (config) => - config.options.externalsPresets?.web || - config.platform?.web || - false, - ); + (this.compiler).compilers.find((config) => Server.isWebTarget(config)); if (compilerWithWebPreset) { return compilerWithWebPreset.options; diff --git a/migration-v6.md b/migration-v6.md index c79377688d..40919f82b9 100644 --- a/migration-v6.md +++ b/migration-v6.md @@ -37,9 +37,9 @@ 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 or when `externalsPresets` includes `web`. +- 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. -Previously, it also injected WebSocket communication if `resolve` contained a `conditionNames` entry with `browser`. +- 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 From cfaa122eb4c40b09b2981967c1098582f5f8dd84 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Mon, 16 Feb 2026 13:45:16 +0000 Subject: [PATCH 3/4] chore: update qs package to version 6.15.0 --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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" From 729712b01df50cac68365488ee6915feaf589a61 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Tue, 17 Feb 2026 13:45:01 +0000 Subject: [PATCH 4/4] fixup! --- lib/Server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Server.js b/lib/Server.js index 41f979e440..41cbe3f654 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -560,7 +560,7 @@ class Server { * @returns {boolean} true when target is `web`, otherwise false */ static isWebTarget(compiler) { - return compiler.platform?.web || false; + return compiler.platform.web || false; } /**