Control which entrypoints participate in federation
Clear and concise description of the problem
The Module Federation plugin currently introduces runtime code to each of the entrypoints that are defined in the bundler config. I'm working in a project that has several entrypoints, with one special entrypoint being responsible for determining which application to load. This special entrypoint doesn't share any code with the other entrypoints, and is intended to be as small as possible.
I'm trying to introduce Module Federation to the project, but one blocker is that currently the special entrypoint now includes all the eagerly shared dependencies and the module federation runtime. The entrypoint doesn't need any of these, and its bundle size is quite a bit larger now.
Is there a way to exclude a particular entrypoint from Module Federation, so that it doesn't receive the runtime or any eagerly loaded modules?
Suggested solution
In the ModuleFederationPlugin there could either be a entries or excludeEntries array to control which entrypoint chunks would be participating in federation.
entry: {
special: './src/entrypoints/special.ts',
'application-one': './src/entrypoints/application-one.ts',
'application-two': './src/entrypoints/application-two.ts',
},
plugins: [
new ModuleFederationPlugin({
entries: ['application-one', 'application-two'] // Only provide the federation runtime to these chunks
})
]
Or
entry: {
special: './src/entrypoints/special.ts',
'application-one': './src/entrypoints/application-one.ts',
'application-two': './src/entrypoints/application-two.ts',
},
plugins: [
new ModuleFederationPlugin({
excludeEntries: ['special'] // Specifically exclude this entrypoint from participating in federation
})
]
Alternative
No response
Additional context
The project I'm working on uses rspack as a bundler
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.
Use hoisted runtime experiment
@ScriptedAlchemy Is the hoisted runtime experiment available in rspack?
I can see it being used in the plugin that is used by Webpack here: https://github.com/module-federation/core/blob/3f9677db6d6e9157d39cdc66f159ac026e67a9e9/packages/enhanced/src/lib/container/ModuleFederationPlugin.ts#L96-L101
I don't see any references to experiments.federationRuntime within the plugin that is used by rspack though:
https://github.com/module-federation/core/blob/3f9677db6d6e9157d39cdc66f159ac026e67a9e9/packages/rspack/src/ModuleFederationPlugin.ts
Not currently. Will implement this quarter
Stale issue message
This has now been solved. It will hoist module into runtime chunk and not duplicate in each entry. As long as you use single runtime chunk optimization.
Stale issue message