Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
54 changes: 6 additions & 48 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.

I think we can up minimum webpack version and don't use compiler.options.externalsPresets?.web all all, also we always have compiler.platform

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.

That sounds good to me. We’ve already bumped the minimum version to webpack 5.101, I just wasn’t sure if you also wanted to remove the externalPresets part.

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.

Yeah, we don't need externalPresets anymore here, only platform, it was literally design for such cases

);
}

/**
Expand Down Expand Up @@ -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) {
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 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.
Expand Down
Loading