refactor(html): drive html dependency extraction by source type#21250
Conversation
🦋 Changeset detectedLatest commit: ab200ac 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 (c1dec16). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@c1dec16
yarn add -D webpack@https://pkg.pr.new/webpack@c1dec16
pnpm add -D webpack@https://pkg.pr.new/webpack@c1dec16 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #21250 +/- ##
=======================================
Coverage 92.80% 92.80%
=======================================
Files 590 590
Lines 64647 64626 -21
Branches 17993 17996 +3
=======================================
- Hits 59996 59979 -17
+ Misses 4651 4647 -4
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:
|
ac0ce14 to
4125366
Compare
Merging this PR will improve performance by 76.97%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "wasm-modules-sync", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
254.5 KB | 352.6 KB | -27.84% |
| ⚡ | Memory | benchmark "lodash", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
850.9 KB | 127 KB | ×6.7 |
| ⚡ | Memory | benchmark "asset-modules-bytes", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
859.2 KB | 246.6 KB | ×3.5 |
| ⚡ | Memory | benchmark "css-modules", scenario '{"name":"mode-production","mode":"production"}' |
9 MB | 7.2 MB | +25.5% |
| ⚡ | Memory | benchmark "many-chunks-esm", scenario '{"name":"mode-production","mode":"production"}' |
9.3 MB | 7.7 MB | +20.61% |
| ⚡ | Memory | benchmark "future-defaults", scenario '{"name":"mode-production","mode":"production"}' |
8.8 MB | 7.3 MB | +20.45% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing refactor/html-parser-type-driven (ab200ac) with main (2e43eb4)
1b5b02f to
f10c898
Compare
Replace the hardcoded `<style>` element, `style=""` attribute, SVG presentation-attribute, inline `<script>` and per-tag attribute branches in the html parser with a single `switch (type)`: a resolved `SourceType` selects the parse algorithm and the dependency kind. No tag-name or attribute-name special cases remain in the dispatch. Add the public `css-url` source type (extracts `url(...)` references from a CSS-valued attribute, e.g. SVG `fill`); SVG presentation attributes now flow through it. Inline `<style>`/`<script>` bodies become table-driven content sources, and `meta` `content` resolves the msapplication-task parser via its type instead of a tag-name check.
f10c898 to
ab200ac
Compare
Summary
The HTML parser previously special-cased
<style>elements,style=""attributes, SVG presentation attributes, inline<script>bodies, and per-tag attributes with separate hardcoded blocks. This refactors all of it to be driven by a single sourcetype: oneswitch (type)resolves the parse algorithm and the dependency kind for every attribute value and element body, so adding a tag/attribute is just a table entry. All sources (per-tag, any-tag, SVG presentation, thestyle=""attribute, and<style>/<script>bodies) live in one source object that developers can extend viamodule.parser.html.sources.A new public
css-urlsourcetypefalls out of this: it extractsurl(...)references from a CSS-valued attribute (e.g. an SVGfill) as plain assets — the built-in SVG presentation handling now flows through it. Behavior is otherwise unchanged.What kind of change does this PR introduce?
refactor (also exposes a new
css-urlsource type)Did you add tests for your changes?
Yes — extended
test/configCases/html/parser-sources-types(newcss-urltype and an any-tag source with notag) and updatedtest/configCases/html/parser-sources-filter. The existingsvg-presentation-url,style-tag,style-attribute,inline-script,script-src,link, … cases (710 html config + cache tests, 118 snapshots) cover the refactored paths unchanged.Does this PR introduce a breaking change?
No. The
sources[].filtersignature is extended backward-compatibly: it now receives(attributes, value)—attributes(the decoded attribute map) stays the first argument, so existing(attributes) => …filters keep working;value(the decoded attribute value) is an added second argument.If relevant, what needs to be documented once your changes are merged or what have you already documented?
The new
module.parser.html.sources[].type: "css-url"value, and the addedvaluesecond argument tosources[].filter. The option schema descriptions inschemas/WebpackOptions.jsonare already updated.Use of AI
AI (Claude Code) was used to perform the refactor, write tests, and regenerate the type declarations, under human direction and review. All changes were verified locally (targeted html test suites,
tsc, ESLint, Prettier, cspell).Generated by Claude Code