Skip to content

Conversation

ScriptedAlchemy
Copy link
Contributor

This pull request introduces tree-shaking support for shared modules in module federation, allowing unused exports in shared modules to be eliminated based on usage information. The implementation involves extending build metadata, updating the plugin system to read usage reports, and adding a new test case to verify the feature.

Tree-shaking for shared modules in module federation:

Core feature implementation:

  • Extended BuildMeta in rspack_core to include new fields (consume_shared_key, shared_key, is_shared_descendant, effective_shared_key) to support export usage tracking for shared modules. [1] [2]
  • Updated the Module trait to provide access to the new consume_shared_key field.

Plugin and runtime changes:

  • Added logic in FlagDependencyUsagePlugin to read a share-usage.json report and update export usage states for shared modules based on this report. [1] [2]
  • Integrated the new ShareUsagePlugin into the ModuleFederationRuntimePlugin flow, ensuring export usage information is processed during compilation. [1] [2] [3] [4]
  • Enhanced the ProvideSharedPlugin to set the shared_key in build metadata for various shared module resolution strategies, enabling correct matching with usage reports. [1] [2] [3] [4]

Supporting changes and tests:

  • Added a new test case (consume-shared-tree-shaking) with a sample shared module, usage report, and configuration to verify that unused exports are correctly tree-shaken. [1] [2] [3] [4]
  • Minor improvements and refactoring in related plugin and module federation code to support the new feature (e.g., new helper methods, dependency imports, and trait adjustments). [1] [2] [3]

Other minor changes:

Development and tooling:

  • Minor formatting and consistency updates in .vscode/launch.json. [1] [2]
  • Added serde as a workspace dependency for rspack_plugin_javascript.

Bugfix:

  • Improved HTTP URI scheme handling to avoid recursive async calls and ensure proper redirect resolution.

These changes collectively enable tree-shaking for shared modules in module federation, improving bundle size and correctness by eliminating unused exports based on actual usage.

ScriptedAlchemy and others added 7 commits August 12, 2025 21:47
…ing prevention

Add ShareUsagePlugin to track shared module usage and prevent tree-shaking for module federation
Add shared_key field to BuildMeta for tree-shaking analysis
Improve ProvideSharedPlugin with better shared module handling
Add documentation explaining module federation tree-shaking behavior
Add detailed documentation explaining:
1. How module federation prevents tree-shaking in Rspack
2. Rspack's tree-shaking implementation details
3. Proposed solution for enabling tree-shaking with module federation
…for-module-federation

Enable parsing share-usage metadata for shared module tree shaking
# Conflicts:
#	Cargo.lock
#	crates/rspack_plugin_mf/src/container/module_federation_runtime_plugin.rs
#	crates/rspack_plugin_mf/src/sharing/consume_shared_plugin.rs
Copy link

netlify bot commented Aug 19, 2025

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit d5dd4a4
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/68a424c046826c00080c6eda
😎 Deploy Preview https://deploy-preview-11413--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Aug 19, 2025
- Remove invalid PluginContext import
- Add missing async_trait import
- Fix apply method signature to match Plugin trait
- Fix context field accesses by removing intermediate .context
- Fix collapsible if statement clippy warning
Copy link
Contributor

📦 Binary Size-limit

Comparing d5dd4a4 to fix(modern-module): correct export alias for json (#11402) by inottn

❌ Size increased by 102.88KB from 47.61MB to 47.71MB (⬆️0.21%)

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.

1 participant