TreeShakingSharedPlugin
Stability: Experimental
Overview
- Performs on-demand build and export optimization for
shareddependencies based on Module Federation configuration.
Options
mfConfig:ModuleFederationPluginOptions, configuration passed to the Module Federation plugin.secondary: whether to perform a second tree-shake during independent builds (typically used when the deployment platform has determined complete dependency info and triggers a fresh build to improve tree-shake accuracy for shared dependencies).
Usage
rspack.config.mjs
Behavior
- Normalizes
sharedinto[shareName, SharedConfig][]. - Registers
SharedUsedExportsOptimizerPluginwhensecondaryisfalseto inject used-exports from the stats manifest. - Creates an independent build only for shared dependencies that enable
treeShakingand retain a local implementation (that is,importis notfalse). - When
mfConfig.manifestis enabled, records the independent build output in the stats and manifest files so the runtime can load it as a fallback.

