feat(asset): add [containedpath] and [containedfile] placeholders - #21592
Merged
Conversation
🦋 Changeset detectedLatest commit: 0cc4ab4 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 |
`[path]`/`[file]` of a module resolved outside of `context` (e.g. a hoisted node_modules in a workspace) start with `..`, so the asset ends up outside of `output.path`. The new placeholders replace an absolute root or a leading `..` with `_`, as file-loader did.
Local copies of `ABSOLUTE_PATH_REGEXP`-style regexps drift apart, so the guide now points at the one file that owns them and says to export from there when something is missing.
`[path]`/`[file]` of an asset module outside of `context` behave like `[containedpath]`/`[containedfile]` with `experiments.futureDefaults`, so the webpack 6 default no longer emits above `output.path`. Only the templates deciding where the asset is written are affected; `generator.publicPath` is a url prefix and keeps the real path, as does `assetInfo.sourceFilename`.
…ults `HtmlModulesPlugin` builds its source filename the same way as `AssetGenerator` and feeds it to `output.htmlFilename`, so a page resolved outside of `context` escaped `output.path` too. Both now go through a shared `toTemplateSourceFileName`.
alexander-akait
force-pushed
the
feat/asset-contained-path
branch
from
August 3, 2026 13:47
a764807 to
0cc4ab4
Compare
Contributor
|
This PR is packaged and the instant preview is available (318421e). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@318421e
yarn add -D webpack@https://pkg.pr.new/webpack@318421e
pnpm add -D webpack@https://pkg.pr.new/webpack@318421e |
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21592 +/- ##
==========================================
- Coverage 94.09% 94.08% -0.01%
==========================================
Files 627 627
Lines 77209 77238 +29
Branches 22656 22667 +11
==========================================
+ Hits 72646 72672 +26
- Misses 4563 4566 +3
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:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #14392.
[path]/[file]of an asset module resolved outside ofcontext(e.g. a hoistednode_modulesin a workspace) start with.., so the asset is written outside ofoutput.path. The new[containedpath]/[containedfile]placeholders replace an absolute root or a leading..with_, asloader-utilsdid forfile-loader, and[path]/[file]of asset modules behave the same way withexperiments.futureDefaults(webpack 6 default).What kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes —
test/configCases/asset-modules/containedpath,test/configCases/asset-modules/path-outside-context-future-defaultsandtest/TemplatedPathPlugin.unittest.js(which also pins that[path]/[file]keep their..without the flag).Does this PR introduce a breaking change?
No.
[path]/[file]only change underexperiments.futureDefaults, where an asset of a module outside ofcontextmoves from outsideoutput.pathto_/…inside it. Only the templates deciding where the asset is written are affected —generator.publicPathis a url prefix andassetInfo.sourceFilenamekeep the real path.If relevant, what needs to be documented once your changes are merged or what have you already documented?
The
[containedpath]/[containedfile]placeholders in the template strings documentation, and theexperiments.futureDefaultsbehaviour of[path]/[file]for asset modules.Use of AI
Yes — Claude Code was used to investigate the issue, write the implementation and tests, and run the test suites. Every design decision (the placeholder names, gating the behaviour change behind
experiments.futureDefaultsinstead of changing the default, and dropping an earlier build warning) was made and reviewed by me.Generated by Claude Code
Note
Medium Risk
Changes where assets and HTML pages are written when futureDefaults is on or templates use the new placeholders; public URLs and sourceFilename metadata are intentionally split from emit paths.
Overview
Adds
[containedpath]and[containedfile]template placeholders so emitted asset paths stay underoutput.path: absolute roots and leading../segments become_/, matching historicalfile-loaderbehavior.With
experiments.futureDefaults, asset and HTML filename templates (notgenerator.publicPath) see contained paths for[path]/[file]viatoTemplateSourceFileNameinAssetGeneratorandHtmlModulesPlugin.assetInfo.sourceFilenamestill records the real context-relative path.TemplatedPathPlugincentralizestoContainedPathusing shared regexps fromlib/util/identifier.js;AGENTS.mddocuments that path regexps must not be duplicated locally.Reviewed by Cursor Bugbot for commit 0cc4ab4. Bugbot is set up for automated code reviews on this repo. Configure here.