Skip to content

feat: use compiler.platform to determine the target#5647

Merged
bjohansebas merged 4 commits intonextfrom
platform
Feb 17, 2026
Merged

feat: use compiler.platform to determine the target#5647
bjohansebas merged 4 commits intonextfrom
platform

Conversation

@bjohansebas
Copy link
Member

@bjohansebas bjohansebas commented Feb 16, 2026

Summary

The use of compiler.platform is available starting from webpack 5.92.0 (webpack/webpack@e11fb12).

The logic that added WebSocket communication when a conditionNames entry included browser has been removed. However, I’m not sure whether we also want to remove the behavior related to externalsPresets. Do we want to remove that as well?

If you want to know where it determines whether the web is available for a specific target, take a look here (https://github.com/webpack/webpack/blob/c835794b7fcd9f1e2f6750ae94c95aadf23a63dd/lib/config/target.js#L101)
What kind of change does this PR introduce?

refactor, and feat

Did you add tests for your changes?

Does this PR introduce a breaking change?

If relevant, what needs to be documented once your changes are merged or what have you already documented?

@codecov
Copy link

codecov bot commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.54%. Comparing base (a4012b6) to head (729712b).
⚠️ Report is 1 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5647      +/-   ##
==========================================
+ Coverage   83.52%   83.54%   +0.01%     
==========================================
  Files          11       11              
  Lines        1936     1920      -16     
  Branches      716      706      -10     
==========================================
- Hits         1617     1604      -13     
+ Misses        286      283       -3     
  Partials       33       33              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

lib/Server.js Outdated

return webTargets.includes(/** @type {string} */ (compiler.options.target));
return (
compiler.platform?.web || compiler.options.externalsPresets?.web || false
Copy link
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
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
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

lib/Server.js Outdated
}

return webTargets.includes(/** @type {string} */ (compiler.options.target));
return compiler.platform?.web || false;
Copy link
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
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.

}

return webTargets.includes(/** @type {string} */ (compiler.options.target));
return compiler.platform.web || false;
Copy link
Member

Choose a reason for hiding this comment

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

Oh, forgot, we need to improve support of universal target too, i.e. target: "node" | "web", i..e when web === null && node === null, but in our client code we should not run code when it is node environment and run when it is web , but let's do it in other PR

@alexander-akait
Copy link
Member

Feel free to merge

@bjohansebas bjohansebas merged commit 6cd1752 into next Feb 17, 2026
89 of 151 checks passed
@bjohansebas bjohansebas deleted the platform branch February 17, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments