feat: expose importAttributes to loaders via _importAttributes#20232
feat: expose importAttributes to loaders via _importAttributes#20232samarthsinh2660 wants to merge 6 commits intowebpack:mainfrom
Conversation
|
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
|
|
@samarthsinh2660 Could you please check the lint failure? |
Thanks for the heads-up. |
aa878d8 to
9e3eaa7
Compare
|
We also need to handle |
okay i will do it |
7ce0722 to
a7bb93d
Compare
…tAttributes, revert generate-types-config.js
a7bb93d to
c5ad681
Compare
|
Hii @samarthsinh2660 I would like to work on this issue. Could you please assign it to me? |
|
No need to work it on, it is under discussion that is why it was not merged |
|
Hi @alexander-akait,
Thanks for the clarification. I understand that the feature is currently
under discussion.
I’ll keep an eye on the discussion and contribute again if needed.
Thanks!
…On Fri, Mar 6, 2026 at 9:09 PM Alexander Akait ***@***.***> wrote:
*alexander-akait* left a comment (webpack/webpack#20232)
<#20232 (comment)>
No need to work it on, it is under discussion that is why it was not merged
—
Reply to this email directly, view it on GitHub
<#20232 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BMXRVI65LWDRWJKPWAD6PT34PLWL5AVCNFSM6AAAAACO3XT6ACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DAMJSGQ3TEMZQG4>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Summary
This PR exposes
importAttributesto the loader interface so loaders can react to metadata onimport/import()statements, as requested in #20228.Today, the parser already understands import attributes, and they are used for things like rule matching, but loaders cannot see them. This change threads the parsed
ImportAttributesfrom the dependency/resolve data into NormalModule and then into the loader context as_importAttributes, so loaders can read them viathis._importAttributes.High-level implementation:
importAttributesin thecreateDatapassed to NormalModule.importAttributeson NormalModule instances._importAttributes, following the pattern of other internal context fields like_module,_compilation, etc._importAttributes?: Record<string, unknown>.configCasestest case undertest/configCases/loaders/import-attributes-loader-context:this._importAttributesand exports it.undefinedis produced when no attributes are present.What kind of change does this PR introduce?
Feature.
It adds a new capability for loaders to inspect the import attributes of the module they are processing (via
_importAttributeson the loader context).Did you add tests for your changes?
Yes.
node node_modules/jest/bin/jest.js test/ConfigTestCases.basictest.js --no-coverage --runInBand --testNamePattern=import-attributes-loader-context--testNamePattern="loaders import-attributes"to ensure existing cases still pass.On my Windows environment, running the full Jest suite surfaces unrelated snapshot differences (absolute paths vs
<cwd>) and missing optional dependencies like@swc/core/esbuild, which appear to be environment-specific and not related to this change.Does this PR introduce a breaking change?
No.
_importAttributeson the loader context.If relevant, what needs to be documented once your changes are merged or what have you already documented?
_importAttributes(an object of import attributes when present, otherwiseundefined) for modules that were imported with attributes._importAttributes(e.g., treating assets differently whenwith { type: "image", preload: true }is used).undefined.