feat: add output.workerChunkFilename to set the worker chunk filename template#21128
Conversation
🦋 Changeset detectedLatest commit: a629385 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 (87394de). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@87394de
yarn add -D webpack@https://pkg.pr.new/webpack@87394de
pnpm add -D webpack@https://pkg.pr.new/webpack@87394de |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21128 +/- ##
==========================================
+ Coverage 92.33% 92.34% +0.01%
==========================================
Files 581 581
Lines 62942 63288 +346
Branches 17420 17507 +87
==========================================
+ Hits 58117 58443 +326
- Misses 4825 4845 +20
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:
|
… caching A function-valued worker filename stored in the AsyncDependenciesBlock broke persistent caching of the worker-creating module. Apply it to the worker entrypoint chunk from outputOptions in afterChunks instead. https://claude.ai/code/session_01NBzMSamAkDoccgnWuENzJj
Merging this PR will improve performance by 33.71%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Memory | benchmark "css-modules", scenario '{"name":"mode-production","mode":"production"}' |
9.1 MB | 6.7 MB | +36.74% |
| ⚡ | Memory | benchmark "asset-modules-bytes", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
321.8 KB | 246.1 KB | +30.74% |
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/worker-chunk-filename (a629385) with main (41985a4)
…d of a hook Worker entry chunks are non-initial entrypoints, so getChunkFilenameTemplate (and the runtime chunk-filename closure) can return output.workerChunkFilename directly via chunk.getEntryOptions(). Removes the WorkerPlugin afterChunks hook and the per-block filename, avoiding chunk mutation and the cache issue entirely. https://claude.ai/code/session_01NBzMSamAkDoccgnWuENzJj
…er chunk loading) The workers loaded a dynamically-imported sub-chunk, whose in-worker chunk loading fails on node 12.17 (works on 14+). Use a static import so the worker is self-contained; it still covers workerChunkFilename on the worker entry. https://claude.ai/code/session_01NBzMSamAkDoccgnWuENzJj
…he entry Name every chunk reachable solely from worker entrypoints (the worker entry chunk and its internal async chunks) with output.workerChunkFilename. Chunks also reachable from an initial entrypoint (shared) stay on output.chunkFilename. Computed in afterOptimizeChunks via getAllReferencedChunks; the pass is skipped unless a distinct workerChunkFilename is set and workers exist. https://claude.ai/code/session_01NBzMSamAkDoccgnWuENzJj
Apply output.workerChunkFilename only to the worker script itself (a non-initial entry chunk). Chunks a worker loads internally via import() are not entry chunks and keep using output.chunkFilename. Resolved via chunk.getEntryOptions() in getChunkFilenameTemplate and the runtime chunk-filename helper; no seal-time pass needed. https://claude.ai/code/session_01NBzMSamAkDoccgnWuENzJj
…m entry options Set `worker: true` on the worker entry's EntryOptions in WorkerPlugin and key the workerChunkFilename lookup off that flag, so a non-worker async entrypoint is no longer treated as a worker. https://claude.ai/code/session_01NBzMSamAkDoccgnWuENzJj
…rkers `webpackEntryOptions` only applies to workers; emit a warning when it is used in a dynamic `import()`. Add a worker test that loads multiple chunks to confirm they all keep `chunkFilename` while only the worker entry uses `workerChunkFilename`. https://claude.ai/code/session_01NBzMSamAkDoccgnWuENzJj
Warn only when the internal `worker` entry option is set via a dynamic `import()`, instead of warning on any `webpackEntryOptions`. https://claude.ai/code/session_01NBzMSamAkDoccgnWuENzJj
Expose `worker` as a documented entry-description option so an entry can be built as a worker (and reused from another entry) directly in `webpack.config.js`, driving `output.workerChunkFilename`. The marker now lives on the public entry schema instead of an internal-only typedef. https://claude.ai/code/session_01NBzMSamAkDoccgnWuENzJj
…untimePlugin Drop the duplicated worker/initial/chunk filename selection from the getChunkScriptFilename runtime closure and delegate to the existing static, mirroring how the CSS path uses CssModulesPlugin. https://claude.ai/code/session_01NBzMSamAkDoccgnWuENzJj
Summary
Adds
output.workerChunkFilenameso the filename template of worker chunks can be set independently ofoutput.chunkFilename/output.filename.WorkerPluginapplies it to the worker entrypoint'sfilename, so it scopes only to worker chunks; per-workerwebpackEntryOptions.filenamestill wins. Defaults tooutput.chunkFilename.Closes #17002.
Closes #19280
What kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes —
test/configCases/worker/worker-chunk-filename(string/function forms across filename/chunkFilename combinations) andtest/configCases/worker/worker-chunk-filename-multiple-entries(confirms it targets only the worker, not other entries); updatedDefaults.unittest.js,Validation.test.js,Cli.basictest.jssnapshots.Does this PR introduce a breaking change?
No. Because it defaults to
output.chunkFilename, worker entry filenames now followchunkFilename(previouslyfilename) when the two differ; setworkerChunkFilenameexplicitly to opt out.If relevant, what needs to be documented once your changes are merged or what have you already documented?
Document
output.workerChunkFilename: filename template for non-initial worker files, same type asoutput.chunkFilename, defaultoutput.chunkFilename.Use of AI
AI (Claude Code) was used to port the change onto current
main, regenerate the auto-generated types/schemas, and write the tests; all changes were reviewed by a human.Generated by Claude Code