Repository navigation
feat: default experiments.css/html/asyncWebAssembly to "auto" - #21365
Conversation
🦋 Changeset detectedLatest commit: f93ec13 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 (a3773f5). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@a3773f5
yarn add -D webpack@https://pkg.pr.new/webpack@a3773f5
pnpm add -D webpack@https://pkg.pr.new/webpack@a3773f5 |
Merging this PR will not alter performance
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "react", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
159.5 KB | 602.6 KB | -73.52% |
| ❌ | Memory | benchmark "cache-filesystem", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
1 MB | 1.7 MB | -41.39% |
| ❌ | Memory | benchmark "json-modules", scenario '{"name":"mode-development","mode":"development"}' |
509.9 KB | 771.8 KB | -33.93% |
| ⚡ | Memory | benchmark "many-modules-esm", scenario '{"name":"mode-development","mode":"development"}' |
1,197.6 KB | 647.8 KB | +84.88% |
| ⚡ | Memory | benchmark "wasm-modules-async", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
330 KB | 194.3 KB | +69.81% |
| ⚡ | Memory | benchmark "many-modules-commonjs", scenario '{"name":"mode-development","mode":"development"}' |
1,220.2 KB | 808.4 KB | +50.93% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing feat/experiments-css-html-wasm-auto (f93ec13) with main (20a9db3)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21365 +/- ##
==========================================
+ Coverage 92.80% 92.82% +0.02%
==========================================
Files 595 595
Lines 67133 67191 +58
Branches 18794 18831 +37
==========================================
+ Hits 62301 62373 +72
+ Misses 4832 4818 -14
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:
|
ea65b72 to
0d52286
Compare
0d52286 to
dce5e66
Compare
dce5e66 to
6121120
Compare
Default `experiments.css`, `experiments.html` and `experiments.asyncWebAssembly` to `"auto"`, which enables the built-in module type unless the user already registers a loader (or explicit type) for those files — so enabling them by default does not break existing css-loader/html-loader/wasm-loader setups. Detection lives on `RuleSetCompiler.hasRuleForResource` (reusing `compileCondition`): it walks `module.rules` (including `oneOf`/`rules`), treats `include`/`exclude` leniently, ignores `enforce: "pre"|"post"` loaders, and also counts a `test` regexp that references the extension so filename-scoped loaders are detected. `asyncWebAssembly` "auto" defers to `syncWebAssembly`. Auto-enabled html/css stay below `.js` in the ESM resolve extensions (only an explicit opt-in keeps `.html` ahead of `.js`), and `devtool` is resolved after experiments so auto-enabled css still gets the default dev css source map.
6121120 to
029c667
Compare
Enabling `experiments.html` by default applies HtmlModulesPlugin to every build. Its lazy `require`s inside the newCompilation hook crashed a watch rebuild that raced after Jest teardown; hoisting them to module scope fixes that and avoids re-requiring per compilation. Keep the no-loader Errors case opted out of the html experiment so it still exercises that path.
Types CoverageCoverage after merging feat/experiments-css-html-wasm-auto into main will be
Coverage Report |
Summary
The built-in CSS, HTML and async-WebAssembly module types currently require an explicit
experimentsopt-in. This defaultsexperiments.css,experiments.htmlandexperiments.asyncWebAssemblyto a new"auto"value that enables the built-in module type only when the user hasn't already registered a loader (or explicittype) for those files, so it stays non-breaking for existingcss-loader/mini-css-extract-plugin/html-loader/wasm-loader setups. Detection lives onRuleSetCompiler.hasRuleForResource(reusingcompileCondition): it walksmodule.rules(incl.oneOf/rules), treatsinclude/excludeleniently, ignoresenforce: "pre"|"post"loaders, and also counts atestregexp that references the extension so filename-scoped loaders are detected;asyncWebAssembly"auto" additionally defers tosyncWebAssembly. Auto-enabled html/css stay below.jsin the ESM resolve extensions (only an explicit opt-in keeps.htmlahead of.js), anddevtoolis resolved after experiments so auto-enabled css still gets the default dev css source map.What kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes —
test/Defaults.unittest.js(auto-resolution matrix across css/html/wasm incl. sass/less, filename-scoped andenforce:preloaders, resolve-extension priority, and the dev css source map) plus newtest/configCases/css/{auto-default,auto-loader,auto-sass-like}; the wasm/html cases that assert the disabled path now opt out explicitly.Does this PR introduce a breaking change?
Behavioral but guarded: the built-in css/html/async-wasm support now activates by default when no loader handles those files, so a
.css/.html/.wasmimport that previously errored now builds. Existing loader-based setups are detected and left untouched; opt out any time withexperiments.{css,html,asyncWebAssembly}: false.If relevant, what needs to be documented once your changes are merged or what have you already documented?
The
experiments.{css,html,asyncWebAssembly}defaults and the new"auto"value should be documented in the experiments section on webpack.js.org.Use of AI
AI (Claude) was used substantially to implement, test and verify this change — including writing the detection logic and tests, and validating no regressions by running the
css-loader,mini-css-extract-plugin,html-loaderandsass-loadersuites plus an end-to-end wasm build against this branch.Generated by Claude Code