refactor: create dedicated module classes per module type#21164
Conversation
Resolve the TODO in AssetModulesPlugin by introducing AssetModule and add dedicated NormalModule subclasses for the remaining built-in module types: JavascriptModule, JsonModule, HtmlModule and SyncWasmModule (CssModule and AsyncWasmModule already existed). Extract AsyncWasmModule into its own file matching its serialization id and register all module classes in internalSerializables so they deserialize from cold caches. NormalModule.deserialize now uses `new this` so subclasses without extra constructor options inherit it. https://claude.ai/code/session_01KFWmBmcxQ7HjZmTDCdnJrZ
Add a `moduleClasses` Map (type -> class) with a `(createData, resolveData)` constructor contract. Built-in module types register their class instead of tapping `createModuleClass`; the hook remains checked first as the override/escape hatch. CssModule and AsyncWasmModule now derive their type-specific properties from resolveData in their constructors. AssetModulesPlugin stays on the hook because `sideEffectFree` comes from plugin options. https://claude.ai/code/session_01KFWmBmcxQ7HjZmTDCdnJrZ
Reverts the moduleClasses registry experiment; the hook-based approach stays for now and the registry idea can be revisited later. https://claude.ai/code/session_01KFWmBmcxQ7HjZmTDCdnJrZ
🦋 Changeset detectedLatest commit: bf97859 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 (7917dd1). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@7917dd1
yarn add -D webpack@https://pkg.pr.new/webpack@7917dd1
pnpm add -D webpack@https://pkg.pr.new/webpack@7917dd1 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21164 +/- ##
==========================================
+ Coverage 92.37% 92.57% +0.19%
==========================================
Files 581 587 +6
Lines 63533 63571 +38
Branches 17606 17606
==========================================
+ Hits 58686 58848 +162
+ Misses 4847 4723 -124
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 44.96%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "lodash", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
124.7 KB | 859.1 KB | -85.48% |
| ❌ | Memory | benchmark "asset-modules-inline", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
217.4 KB | 319.1 KB | -31.86% |
| ❌ | Memory | benchmark "devtool-source-map", scenario '{"name":"mode-development","mode":"development"}' |
993.9 KB | 1,309.9 KB | -24.12% |
| ⚡ | Memory | benchmark "devtool-eval", scenario '{"name":"mode-production","mode":"production"}' |
7.8 MB | 6.4 MB | +22.27% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing refactor/dedicated-module-classes (bf97859) with main (30b18a6)
Summary
Resolves the long-standing TODO in
AssetModulesPluginby introducing dedicatedNormalModulesubclasses for all built-in module types:JavascriptModule,AssetModule,JsonModule,HtmlModuleandSyncWasmModule(CssModuleandAsyncWasmModulealready existed).AssetModulenow owns the side-effect-free logic,AsyncWasmModulemoved into its own file matching its serialization id, and all module classes are registered ininternalSerializablesso they deserialize correctly from cold persistent caches.What kind of change does this PR introduce?
refactor
Did you add tests for your changes?
Yes —
test/configCases/module-classes/covers all dedicated classes (js, json, asset, css, html, sync/async wasm) and the asset side-effect-free behavior, in both normal and filesystem-cache variants.Does this PR introduce a breaking change?
No — module identifiers and behavior are unchanged; the new classes are
NormalModulesubclasses.If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a
Use of AI
AI (Claude Code) was used to implement the change, write the tests and run the verification suites, directed and reviewed by the author.
https://claude.ai/code/session_01KFWmBmcxQ7HjZmTDCdnJrZ
Generated by Claude Code