Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control which entrypoints participate in federation #3388

Open
2 tasks done
sfc-gh-jdaly opened this issue Dec 20, 2024 · 3 comments
Open
2 tasks done

Control which entrypoints participate in federation #3388

sfc-gh-jdaly opened this issue Dec 20, 2024 · 3 comments

Comments

@sfc-gh-jdaly
Copy link

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

  • Read the Contributing Guidelines.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@ScriptedAlchemy
Copy link
Member

Use hoisted runtime experiment

@sfc-gh-jdaly
Copy link
Author

@ScriptedAlchemy Is the hoisted runtime experiment available in rspack?

I can see it being used in the plugin that is used by Webpack here:

if (options.experiments?.federationRuntime) {
new FederationModulesPlugin().apply(compiler);
new StartupChunkDependenciesPlugin({
asyncChunkLoading: true,
}).apply(compiler);
}

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

@ScriptedAlchemy
Copy link
Member

Not currently. Will implement this quarter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants