fix(target): report "universal" as the loader target - #21540
#21540fix(target): report "universal" as the loader target#21540alexander-akait merged 2 commits intomainwebpack/webpack:mainfrom fix/universal-loader-targetwebpack/webpack:fix/universal-loader-targetCopy head branch name to clipboard
Conversation
`options.loader.target` fell through to `undefined` for the universal target (`"universal"` / `["web", "node"]` + ESM output), so loaders had no way to tell what they were building for. Also extend the universal coverage across module types: css/auto, css in an async chunk, `data:` uri modules and the loader target in `target/universal-all-module-types`, plus a new `target/universal-html-entry` case covering an html entry with its webmanifest, assets and extracted css.
🦋 Changeset detectedLatest commit: 4e546d0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is packaged and the instant preview is available (9cdcc57). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@9cdcc57
yarn add -D webpack@https://pkg.pr.new/webpack@9cdcc57
pnpm add -D webpack@https://pkg.pr.new/webpack@9cdcc57 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21540 +/- ##
==========================================
- Coverage 93.81% 93.81% -0.01%
==========================================
Files 620 620
Lines 73583 73591 +8
Branches 21267 21273 +6
==========================================
+ Hits 69034 69041 +7
- Misses 4549 4550 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 23.31%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "devtool-eval", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
1.3 MB | 3.1 MB | -57.86% |
| ❌ | Memory | benchmark "many-modules-commonjs", scenario '{"name":"mode-production","mode":"production"}' |
7 MB | 9.2 MB | -24.38% |
| ⚡ | Memory | benchmark "asset-modules-resource", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
1,203.6 KB | 850.5 KB | +41.52% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing fix/universal-loader-target (4e546d0) with main (774e7e4)
options.loader.targetfell through toundefinedfor the universaltarget (
"universal"/["web", "node"]+ ESM output), so loaders had noway to tell what they were building for.
Also extend the universal coverage across module types: css/auto, css in an
async chunk,
data:uri modules and the loader target intarget/universal-all-module-types, plus a newtarget/universal-html-entrycase covering an html entry with its webmanifest, assets and extracted css.
Note
Low Risk
Small default-resolution change in
applyLoaderDefaultswith explicit universal detection; behavior is covered by defaults and config-case tests.Overview
For universal builds (ESM output with web + node, neither platform singled out),
options.loader.targetused to stayundefined, so loaders saw nothis.target.applyLoaderDefaultsnow takesoutputModuleand sets the loader target to"universal"when bothtargetProperties.nodeandtargetProperties.webarenull.Defaults snapshots are updated so universal configs expect
loader.target: "universal"instead ofundefined/"web".Tests add coverage: a loader that exposes
this.targetinuniversal-all-module-types(plus css/auto, async css,data:modules), and a newuniversal-html-entrycase for HTML entry, webmanifest, assets, and extracted CSS.Reviewed by Cursor Bugbot for commit 4e546d0. Bugbot is set up for automated code reviews on this repo. Configure here.