Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: expose importAttributes to loaders via _importAttributes#20232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
samarthsinh2660 wants to merge6 commits intowebpack:main
base:main
Choose a base branch
Loading
fromsamarthsinh2660:feat/loader-import-attributes

Conversation

@samarthsinh2660
Copy link
Contributor

Summary

This PR exposesimportAttributes to 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 parsedImportAttributes from the dependency/resolve data into NormalModule and then into the loader context as_importAttributes, so loaders can read them viathis._importAttributes.

High-level implementation:

  • Extend NormalModuleFactory to includeimportAttributes in thecreateData passed to NormalModule.
  • StoreimportAttributes on NormalModule instances.
  • Expose the stored attributes on the loader context as_importAttributes, following the pattern of other internal context fields like_module,_compilation, etc.
  • Update declarations/LoaderContext.d.ts to include_importAttributes?: Record<string, unknown>.
  • Add aconfigCases test case undertest/configCases/loaders/import-attributes-loader-context:
    • A custom loader readsthis._importAttributes and exports it.
    • One import with attributes and one without, asserting:
      • Attributes object is passed through when present.
      • undefined is 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_importAttributes on the loader context).

Did you add tests for your changes?

Yes.

  • Added a new config test:
    • test/configCases/loaders/import-attributes-loader-context/webpack.config.js
    • test/configCases/loaders/import-attributes-loader-context/loader.js
    • test/configCases/loaders/import-attributes-loader-context/index.js
  • Ran targeted Jest tests for this case:
    • node node_modules/jest/bin/jest.js test/ConfigTestCases.basictest.js --no-coverage --runInBand --testNamePattern=import-attributes-loader-context
  • Also ran loader/import-attributes related config tests via--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.

  • The change only adds a new internal property_importAttributes on the loader context.
  • Existing loaders and configurations continue to work as before.
  • No existing public APIs are removed or changed.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

  • Loader API docs should mention that the loader context now provides_importAttributes (an object of import attributes when present, otherwiseundefined) for modules that were imported with attributes.
  • It may be worth adding:
    • A short example of a loader that branches behavior based on_importAttributes (e.g., treating assets differently whenwith { type: "image", preload: true } is used).
    • A note that this is populated only when the module is reached via an import with attributes and is otherwiseundefined.

@changeset-bot
Copy link

changeset-botbot commentedDec 12, 2025
edited
Loading

⚠️ No Changeset found

Latest commit:7ce0722

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go.If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codspeed-hq
Copy link

codspeed-hqbot commentedDec 12, 2025
edited
Loading

CodSpeed Performance Report

Merging#20232 willnot alter performance

Comparingsamarthsinh2660:feat/loader-import-attributes (7ce0722) withmain (2179fdb)

Summary

✅ 54 untouched
⏩ 18 skipped1

Footnotes

  1. 18 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase,click here and archive them to remove them from the performance reports.

@snitin315
Copy link
Member

@samarthsinh2660 Could you please check the lint failure?

samarthsinh2660 reacted with thumbs up emoji

@samarthsinh2660
Copy link
ContributorAuthor

@samarthsinh2660 Could you please check the lint failure?

Thanks for the heads-up.
I’ll look into the lint failure and push a fix shortly

@samarthsinh2660samarthsinh2660force-pushed thefeat/loader-import-attributes branch fromaa878d8 to9e3eaa7CompareDecember 12, 2025 20:29
@hai-x
Copy link
Member

We also need to handleserialization anddeserialization.

@samarthsinh2660
Copy link
ContributorAuthor

We also need to handleserialization anddeserialization.

okay i will do it

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@alexander-akaitalexander-akaitAwaiting requested review from alexander-akait

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@samarthsinh2660@snitin315@hai-x@alexander-akait

[8]ページ先頭

©2009-2025 Movatter.jp