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

Support Global Plugin Regestration from init #3290

Closed
2 tasks done
yuvalkarif opened this issue Nov 28, 2024 · 6 comments
Closed
2 tasks done

Support Global Plugin Regestration from init #3290

yuvalkarif opened this issue Nov 28, 2024 · 6 comments

Comments

@yuvalkarif
Copy link

yuvalkarif commented Nov 28, 2024

Clear and concise description of the problem

Currently the only options to add global plugins are: registerGlobalPlugins or window.__FEDERATION__.__GLOBAL_PLUGIN__?.push.

There is no option to pass globalPlugins to init.

Suggested solution

Enable passing globalPlugins to the init runtime function, later to be supported from vite / webpack as well.
Example:

import runtimePlugin from 'custom-runtime-plugin.ts';
import globalRuntimePlugin from 'global-custom-runtime-plugin.ts';
init({
  name: '@demo/app-main',
  plugins: [runtimePlugin()],
  globalPlugins: [globalRuntimePlugin()], // <-- New
  remotes: [
    {
      name: "@demo/app2",
      entry: "http://localhost:3006/remoteEntry.js",
      alias: "app2"
    },
  ],
});

Alternative

We can also mark any plugin as global: true to be registered globally.

import { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
export default function (): FederationRuntimePlugin {
  return {
    name: 'custom-plugin-build',
    global: true, // <-- New
    beforeInit(args) {
      console.log('[build time inject] beforeInit: ', args);
      return args;
    },
    beforeLoadShare(args) {
      console.log('[build time inject] beforeLoadShare: ', args);
      return args;
    },
  };
}

Additional context

Willing to take part in the implementation :)

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

Send a pull request. registerPlugins in core.ts

@yuvalkarif
Copy link
Author

Great, will dive into it over the weekend

@ScriptedAlchemy
Copy link
Member

After discussion with the team.
They do not want to make it easy to use global runtime plugins.
This is a very serious act to utilize them, and can cause catastrophic problems if they are overused.

The team would prefer deliberate friction, forcing the user to implement it somewhere else or in the pre-entry phases of the compiler, in their own code, or how i do it - i just register a blank runtime plugin where i use registerGlobalPlugin and just register it anyway as a side-effect of a normal runtime plugin.
The major concern is on-call pressure that supporting this feature will put on us at our company, they want it to be unfriendly and out of reach of most

@yuvalkarif
Copy link
Author

I see, thanks !

@ScriptedAlchemy
Copy link
Member

Sorry man! I Tried!

@yuvalkarif
Copy link
Author

Sorry man! I Tried!

All good :) it was nice experimenting with the codebase, see ya in the next PR 🤞

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