Skip to content

Conversation

@JSerFeng
Copy link
Contributor

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:

  1. One module import namespace from external module won't break optimization for other named imports
  2. External module no need to be in a single chunk

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Jan 22, 2026
@JSerFeng JSerFeng force-pushed the feat/external-improvement branch from 15d99bc to bc7fd87 Compare January 22, 2026 06:31
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 22, 2026

Deploying rspack-v2 with  Cloudflare Pages  Cloudflare Pages

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

View logs

@github-actions
Copy link
Contributor

github-actions bot commented Jan 22, 2026

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 4 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB +189.0 B (0.0%)
react-1k 825.5 KB +189.0 B (0.0%)
react-5k 2.7 MB +189.0 B (0.0%)
rome 985.9 KB 0
ui-components 2.3 MB 📈 +182.1 KB (+8.6%)
📋 Detailed Reports (Click to expand)

📁 react-10k

Path: ../build-tools-performance/cases/react-10k/dist/rsdoctor-data.json

📌 Baseline Commit: 30d58971b9 | PR: #12818

Metric Current Baseline Change
📊 Total Size 5.7 MB 5.7 MB +189.0 B (0.0%)
📄 JavaScript 5.7 MB 5.7 MB +189.0 B (0.0%)
🎨 CSS 21.0 B 21.0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: react-10k Bundle Diff

📁 react-1k

Path: ../build-tools-performance/cases/react-1k/dist/rsdoctor-data.json

📌 Baseline Commit: 30d58971b9 | PR: #12818

Metric Current Baseline Change
📊 Total Size 825.5 KB 825.3 KB +189.0 B (0.0%)
📄 JavaScript 825.5 KB 825.3 KB +189.0 B (0.0%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: react-1k Bundle Diff

📁 react-5k

Path: ../build-tools-performance/cases/react-5k/dist/rsdoctor-data.json

📌 Baseline Commit: 30d58971b9 | PR: #12818

Metric Current Baseline Change
📊 Total Size 2.7 MB 2.7 MB +189.0 B (0.0%)
📄 JavaScript 2.7 MB 2.7 MB +189.0 B (0.0%)
🎨 CSS 21.0 B 21.0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: react-5k Bundle Diff

📁 ui-components

Path: ../build-tools-performance/cases/ui-components/dist/rsdoctor-data.json

📌 Baseline Commit: 30d58971b9 | PR: #12818

Metric Current Baseline Change
📊 Total Size 2.3 MB 2.1 MB +182.1 KB (+8.6%)
📄 JavaScript 2.0 MB 2.0 MB -2.5 KB (-0.1%)
🎨 CSS 267.6 KB 83.0 KB +184.6 KB (+222.4%)
🌐 HTML 0 B 0 B 0
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: ui-components Bundle Diff

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Contributor

github-actions bot commented Jan 22, 2026

📦 Binary Size-limit

Comparing e6a5216 to refactor: remove misleadning naming and adjust cache call place (#12818) by hardfist

❌ Size increased by 8.38KB from 47.69MB to 47.70MB (⬆️0.02%)

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 22, 2026

Merging this PR will not alter performance

✅ 16 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing feat/external-improvement (e6a5216) with main (30d5897)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@JSerFeng JSerFeng force-pushed the feat/external-improvement branch 2 times, most recently from 50f55fd to 08b69b4 Compare January 22, 2026 11:08
@JSerFeng JSerFeng changed the base branch from v2 to main January 22, 2026 11:08
@JSerFeng JSerFeng enabled auto-merge (squash) January 22, 2026 11:08
Timeless0911
Timeless0911 previously approved these changes Jan 22, 2026
@JSerFeng JSerFeng force-pushed the feat/external-improvement branch from 08b69b4 to e6a5216 Compare January 23, 2026 03:45
Copilot AI review requested due to automatic review settings January 23, 2026 03:45
Copy link
Contributor

Copilot AI left a 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_imports function 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.

@JSerFeng JSerFeng merged commit a248d9c into main Jan 23, 2026
56 checks passed
@JSerFeng JSerFeng deleted the feat/external-improvement branch January 23, 2026 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants