core icon indicating copy to clipboard operation
core copied to clipboard

Control which entrypoints participate in federation

Open sfc-gh-jdaly opened this issue 11 months ago • 5 comments

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.

sfc-gh-jdaly avatar Dec 20 '24 18:12 sfc-gh-jdaly

Use hoisted runtime experiment

ScriptedAlchemy avatar Dec 27 '24 08:12 ScriptedAlchemy

@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

sfc-gh-jdaly avatar Jan 03 '25 17:01 sfc-gh-jdaly

Not currently. Will implement this quarter

ScriptedAlchemy avatar Jan 04 '25 02:01 ScriptedAlchemy

Stale issue message

github-actions[bot] avatar Mar 05 '25 15:03 github-actions[bot]

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.

ScriptedAlchemy avatar Mar 15 '25 09:03 ScriptedAlchemy

Stale issue message

github-actions[bot] avatar May 14 '25 15:05 github-actions[bot]