-
-
Notifications
You must be signed in to change notification settings - Fork 759
feat: support MF share treeshake #12250
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
✅ Deploy Preview for rspack canceled.
|
📦 Binary Size-limit
❌ Size increased by 216.38KB from 48.34MB to 48.55MB (⬆️0.44%) |
a55f482 to
4bccd0f
Compare
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
43683b8 to
b49c5b5
Compare
635668b to
98a6db7
Compare
09e0e3f to
611139b
Compare
a052b96 to
2219929
Compare
2219929 to
3c0a94e
Compare
…shaking fix incorrect module name in shared config and test cases change async process_module to sync using block_on for better performance update shared exports optimization to handle side effects properly
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
…ent tree-shaking Add fallback for undefined moduleToHandlerMapping in shared container entry Include additional plugins in filter list and prevent tree-shaking of shared modules by adding console logs when collectShared is true
refactor(node_binding): remove redundant exports in wasi files
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 PR implements tree-shaking support for shared dependencies in Module Federation, allowing for more efficient bundle sizes by eliminating unused exports from shared modules. The implementation spans both Rust (core functionality) and JavaScript/TypeScript (API and runtime).
Changes:
- Adds tree-shaking configuration options to shared dependencies with two modes:
runtime-inferandserver-calc - Implements plugins for collecting and optimizing shared module exports
- Updates runtime to support dynamic loading of tree-shaken shared modules
- Adds comprehensive test coverage for the new functionality
Reviewed changes
Copilot reviewed 84 out of 124 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| website/docs/{en,zh}/plugins/webpack/tree-shaking-shared-plugin.mdx | New documentation for TreeShakingSharedPlugin |
| website/docs/{en,zh}/plugins/webpack/module-federation-plugin.mdx | Documentation for new tree-shaking options |
| packages/rspack/src/sharing/*.ts | TypeScript implementation of tree-shaking plugins |
| packages/rspack/src/container/*.ts | Updates to Module Federation plugin |
| packages/rspack/src/runtime/moduleFederationDefaultRuntime.js | Runtime support for tree-shaking |
| crates/rspack_plugin_mf/src/sharing/*.rs | Rust implementation of tree-shaking logic |
| crates/rspack_plugin_mf/src/container/*.rs | Container entry module changes |
| crates/rspack_core/src/*.rs | Core type additions and dependency handling |
| tests/rspack-test/configCases/sharing/* | Comprehensive test cases |
| pnpm-lock.yaml, package.json | Dependency version updates |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/rspack-test/configCases/container-1-5/tree-shaking-shared-infer-mode/rspack.config.js
Show resolved
Hide resolved
tests/rspack-test/configCases/container-1-5/tree-shaking-shared-server-mode/rspack.config.js
Show resolved
Hide resolved
Add GitHub action for continuous benchmarking with CodSpeed. The action supports multiple measurement modes and instruments, including MongoDB instrumentation and caching for faster runs. Includes validation for required inputs and custom runner installation.
crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs
Outdated
Show resolved
Hide resolved
| .into(); | ||
| plugins.push(CollectSharedEntryPlugin::new(options).boxed()) | ||
| } | ||
| BuiltinPluginName::SharedContainerPlugin => { |
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.
What is SharedContainerPlugin, can this merge into ContainerPlugin with an additional option?
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.
While both plugins share the underlying ContainerEntryDependency , I don't think they should be merged or reused at the plugin level due to their distinct responsibilities and configurations:
- Different Responsibilities : ContainerPlugin is a general-purpose plugin for exposing multiple modules ( exposes ), whereas SharedContainerPlugin is specialized for wrapping a single shared dependency (like react ) into an isolated container, typically used with IndependentSharedPlugin .
- Configuration Structure : ContainerPlugin handles a complex list of exposes map and enhanced mode settings. SharedContainerPlugin focuses on a single request and version without the concept of exposes . Reusing ContainerPlugin here would require awkward parameter conversion (e.g., faking request as an exposes entry), which increases complexity.
- Runtime Behavior : They inject different RuntimeModule s ( ExposeRuntimeModule vs ShareContainerRuntimeModule ). Merging them would introduce unnecessary branching logic.
I believe reusing them at the Dependency level (as they currently do) is the correct level of abstraction.
crates/rspack_plugin_javascript/src/dependency/esm/esm_import_specifier_dependency.rs
Outdated
Show resolved
Hide resolved
Optimize the optimize_dependencies hook to reduce lock contention: - Batch collect module info with single read lock instead of N times - Batch apply mutations with single write lock instead of N times - Pre-compute runtime referenced exports outside of write locks This fixes performance regression introduced by #12250 where each module iteration acquired separate read/write locks on module_graph. Related: #12250
| }, | ||
| "peerDependencies": { | ||
| "@module-federation/runtime-tools": ">=0.22.0", | ||
| "@module-federation/runtime-tools": "0.24.1", |
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.
@2heal1 Why use a fixed version here? Should we include ^0.24.1 and ^2.0.0
| 'SharedUsedExportsOptimizerPlugin', | ||
| 'HtmlWebpackPlugin', | ||
| 'HtmlRspackPlugin', | ||
| 'RsbuildHtmlPlugin', |
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.
Hardcoding an Rsbuild internal plugin name to @rspack/core doesn't seem like good practice...
This plugin class name isn't a public API and is unstable.
Summary
Support shared tree shaking .
It support two modes:
runtime-infer|server-calcto satisfy different demands.View this discusstion for more details .
Related links
Checklist