8000 refactor: improve external module render for libraryType: module by JSerFeng · Pull Request #19416 · webpack/webpack · GitHub
[go: up one dir, main page]

Skip to content

refactor: improve external module render for libraryType: module #19416

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

JSerFeng
Copy link
Contributor
@JSerFeng JSerFeng commented Apr 11, 2025

What kind of change does this PR introduce?

🚧 WIP...

improve output for external module of library.type: module

Before:

import * as __WEBPACK_EXTERNAL_MODULE_external from 'external'
__WEBPACK_EXTERNAL_MODULE_external.foo;

This PR:

import { foo } from 'external'
foo;

ExternalModule is imported though InitFragment, which will insert a namespace import, but user may want to keep the code as is

// input
import { foo } from 'external'
foo;
// output
import * as __WEBPACK_EXTERNAL_MODULE_external from 'external'
__WEBPACK_EXTERNAL_MODULE_external.foo;

As we know the exportsInfo, we can use them to improve the output.

If exportsInfo.getUsedExports() equals:

  • true: used unknown exports from external module, fallback to namespace import like before
  • Set<string>: we know exactly used exports from external module, render them, we should also insert the exported specifier into ConcatenationScope.allUsedNames to avoid conflicts

Did you add tests for your changes?

WIP...

Does this PR introduce a breaking change?

No

What needs to be documented once your changes are merged?

@JSerFeng JSerFeng changed the title refactor: named imports from external module refactor: improve external module render for libraryType: module Apr 11, 2025
@JSerFeng JSerFeng force-pushed the refactor/improve-external-module-exports branch from 63a0edb to 2ad9415 Compare April 15, 2025 11:36
@JSerFeng JSerFeng marked this pull request as ready for review April 16, 2025 09:10
@JSerFeng JSerFeng marked this pull request as draft April 18, 2025 09:21
@alexander-akait
Copy link
Member

@JSerFeng Hello, do you need help here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0