website/docs/en/plugins/webpack/tree-shaking-shared-plugin.mdx
import { Stability, ApiMeta } from '@components/ApiMeta';
Overview
shared dependencies based on Module Federation configuration.Options
mfConfig: ModuleFederationPluginOptions, configuration passed to the Module Federation plugin.plugins: extra plugins reused during independent builds.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
import { TreeShakingSharedPlugin } from '@rspack/core';
export default {
plugins: [
new TreeShakingSharedPlugin({
secondary: true,
mfConfig: {
name: 'app',
shared: {
'lodash-es': { treeShaking: { mode: 'server-calc' } },
},
library: { type: 'var', name: 'App' },
manifest: true,
},
plugins: [],
}),
],
};
Behavior
shared into [shareName, SharedConfig][].SharedUsedExportsOptimizerPlugin when secondary is false to inject used-exports from the stats manifest.tree shaking: true, and writes the produced assets back to the stats/manifest (fallback fields).