add option to exclude shared dependencies from build
Clear and concise description of the problem
I use rsbuild for building, and want to minimize my remote module size, so I don't want shared dependencies generated on remotes as I can load it from my host. I tried these config in rsbuild.config.ts:
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack'
......
output: {
externals: ["react"]
},
tools: {
rspack: (config, { appendPlugins }) => {
appendPlugins([
new ModuleFederationPlugin({
shared: {
react: { singleton: true }
}
})
}
}
but where I run rsbuild build, shared react is still generated at:
dist\static\js\async\lib-react.e00de504.js
Suggested solution
add ModuleFederationPluginOptions options:
/* exclude shared dependencies from build, default: false */
external?: boolean
Alternative
No response
Additional context
No response
Validations
- [X] Read the Contributing Guidelines.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
you can set shared: { react: { import:false } }
{ import: false } means shared will not be bundled into dist
you can set
shared: { react: { import:false } }
@2heal1 I tried it, not work, still lib-react.xxxxxxxx.js generated
+1
react-lib is a chunk group. It includes react, react-dom, react/jsx-runtime, schedular. Youd need to look through the chunks contents and make them all external. react-lib is just a name, might not even have react in it if you look closer
pluginReact({splitChunks: {react: false, router: false}}) or something like that. Will disable the react chunk group entirely
You can try writing a Webpack plugin,like this:
compiler.hooks.thisCompilation.tap(this.PLUGIN_NAME, (compilation, { normalModuleFactory }) => {
normalModuleFactory.hooks.afterResolve.tap(this.PLUGIN_NAME, ({ context, request }) => {
if (this.cropShared.includes(request)) {
return false
}
})
})
Stale issue message