Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 2 additions & 51 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove ? here, you got it because webpack compiler can be Compiler or MultiCompiler, so you need

if (Array.isArray(compiler)) {
  return compiler.some((r) => compiler.platform.web);
}

return compiler.platform.web;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, the "?" is not necessary. And when this function is called, it will be a compiler, not a multi-compiler (

addAdditionalEntries(compiler) {
,
this.addAdditionalEntries(compiler);
are already compilers and not multi-compilers). It could be considered a new feature if that’s what you want.

}

/**
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions migration-v6.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading