feat: add defineConfig helper for typed configuration files#21169
Conversation
🦋 Changeset detectedLatest commit: e73a48b 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 (4fa6844). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@4fa6844
yarn add -D webpack@https://pkg.pr.new/webpack@4fa6844
pnpm add -D webpack@https://pkg.pr.new/webpack@4fa6844 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21169 +/- ##
=======================================
Coverage 92.71% 92.72%
=======================================
Files 589 590 +1
Lines 64190 64194 +4
Branches 17806 17806
=======================================
+ Hits 59514 59522 +8
+ Misses 4676 4672 -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:
|
Merging this PR will improve performance by 80.34%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Memory | benchmark "asset-modules-inline", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
1,294.5 KB | 221.4 KB | ×5.8 |
| ⚡ | Memory | benchmark "side-effects-reexport", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
1,203.3 KB | 769.5 KB | +56.36% |
| ⚡ | Memory | benchmark "future-defaults", scenario '{"name":"mode-production","mode":"production"}' |
11.8 MB | 8.8 MB | +33.73% |
| ⚡ | Memory | benchmark "asset-modules-bytes", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
320.2 KB | 246.3 KB | +30% |
| ⚡ | Memory | benchmark "context-esm", scenario '{"name":"mode-production","mode":"production"}' |
8.8 MB | 7.3 MB | +20.06% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing feat/define-config (e73a48b) with main (31def43)
22ac203 to
62189fc
Compare
Extends prepareOptions and the config test runner to support async function and promise configs, staying synchronous for sync configs. https://claude.ai/code/session_01YMzDH3ktTFRaGeATwQxqaY
42fa454 to
f24d15e
Compare
Summary
Add a
defineConfighelper (a typed identity function, like in Vite/Rollup/Rspack) so configuration files get type hints and validation without JSDoc annotations; it accepts every shape webpack-cli already loads — object, multi-compiler array, function style, and promises thereof.What kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes —
test/DefineConfig.unittest.jsandtest/configCases/simple/define-config{,-function,-multi-compiler}/.Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
Document
webpack.defineConfigon the configuration documentation pages.Use of AI
This PR was implemented with Claude Code under my direction and review; I specified the design (export + types only, reusing webpack-cli's existing function-config support).
Generated by Claude Code