-
-
Notifications
You must be signed in to change notification settings - Fork 757
feat: improve external module rendering #12813
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
Conversation
15d99bc to
bc7fd87
Compare
Deploying rspack-v2 with
|
| Latest commit: |
e6a5216
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6b9ccfb1.rspack-v2.pages.dev |
| Branch Preview URL: | https://feat-external-improvement.rspack-v2.pages.dev |
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 4 projects with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 react-10kPath:
📦 Download Diff Report: react-10k Bundle Diff 📁 react-1kPath:
📦 Download Diff Report: react-1k Bundle Diff 📁 react-5kPath:
📦 Download Diff Report: react-5k Bundle Diff 📁 ui-componentsPath:
📦 Download Diff Report: ui-components Bundle Diff Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
❌ Size increased by 8.38KB from 47.69MB to 47.70MB (⬆️0.02%) |
Merging this PR will not alter performance
Comparing Footnotes
|
50f55fd to
08b69b4
Compare
08b69b4 to
e6a5216
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request improves external module rendering by creating separate external module instances for each importing module, enabling better optimization when different modules import different members from the same external.
Changes:
- Modified external module identifiers to include issuer information, allowing separate instances per importing module
- Extended import specification data structures to track namespace imports alongside named and default imports
- Refactored import rendering logic into a reusable
render_importsfunction that handles all import types (namespace, default, and named)
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rspack_core/src/external_module.rs | Removed direct import fragment generation, now using concatenation scope for namespace imports; added set_id method |
| crates/rspack_core/src/concatenated_module.rs | Added ConcatenatedImportMapItem struct with namespace support; created render_imports function; updated import accumulation logic |
| crates/rspack_core/src/utils/concatenation_scope.rs | Added register_namespace_import method to handle namespace import registration |
| crates/rspack_core/src/normal_module_factory.rs | Added after_factorize hook to allow module transformation after creation |
| crates/rspack_plugin_esm_library/src/plugin.rs | Implemented after_factorize hook to modify external module identifiers with issuer information |
| crates/rspack_plugin_esm_library/src/render.rs | Refactored to use new render_imports function |
| crates/rspack_plugin_esm_library/src/link.rs | Updated import tracking and deduplication logic to handle namespace imports |
| tests/rspack-test/esmOutputCases/externals/multiple-externals/* | New test case verifying correct handling of mixed import types from same external |
| tests/rspack-test/esmOutputCases/re-exports/deep-re-exports-esm-4/rspack.config.js | Removed empty configuration file |
| Various snapshot files | Updated to reflect new external module rendering with hash suffixes and blank lines |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
External module can now be separate from each module. Before one external instance is shared by different modules.
Which means 2 modules can import different members of it, moduleA imports specifierA, and moduleB imports the namespace, if 2 modules are in different chunks, that will make the external module to be extracted in to a single chunk. And because of module B imports namespace, we have to make sure the external module export namespace, and it's hard to optimize it for moduleA.
In this PR, EsmLibraryPlugin will modify external module identifier, which makes each external imported by different modules can have different instances.
The benefit:
Related links
Checklist