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

runtimePlugins support pass parameters #1980

Open
2 tasks done
2heal1 opened this issue Jan 16, 2024 · 6 comments
Open
2 tasks done

runtimePlugins support pass parameters #1980

2heal1 opened this issue Jan 16, 2024 · 6 comments
Labels
✨ enhancement New feature or request
Milestone

Comments

@2heal1
Copy link
Member

2heal1 commented Jan 16, 2024

Clear and concise description of the problem

Now ModuleFederationPlugin support runtimePlugins option , but it can not pass parameters , so the usage is limited .

Suggested solution

runtimePlugins support pass parameters by array config . The first item is runtimePlugin path , and the second item is a serializable parameter configuration.

The type is like this:

type RuntimePlugins = Array<string> | Array<[string, unknown]>

// config file

new ModuleFederationPlugin {
 runtimePlugins: [ 
    path.resolve( 'my-custom-plugin.js'),
    [ 
       path.resolve( 'my-custom-plugin-with-parameters.js'),
       { customOptions: 'xxxx' },
    ]
   ]
}

Alternative

No response

Additional context

No response

Validations

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

2heal1 commented Jan 16, 2024

@ahabhgk What do you think about it ? Can we do it in rspack as well ?

@ahabhgk
Copy link

ahabhgk commented Jan 16, 2024

We can implement this, but since runtimePlugins are running in runtime not build time, so there is a limitation about the parameters, which need to be serializable if you use it in the config file, but if you use it in runtime, there won't be this limitation.

@2heal1
Copy link
Member Author

2heal1 commented Jan 16, 2024

We can implement this, but since runtimePlugins are running in runtime not build time, so there is a limitation about the parameters, which need to be serializable if you use it in the config file, but if you use it in runtime, there won't be this limitation.

yes , the parameters must be serializable . If the users want to pass function , they can just add parameters in plugin , like this :

import { FederationRuntimePlugin } from '@module-federation/runtime';

export default function (): FederationRuntimePlugin {
  const options = {xxxx} 
  return {
     beforeInit(args){
         if(options){
            // do something
         }
         return args;
     }
  }
}

@ScriptedAlchemy
Copy link
Member

yeah i used to do this trick with __resourceQuery and put things on the query string of an import to use at runtime. Same limits apply :P

@zhoushaw zhoushaw added the ✨ enhancement New feature or request label Jan 22, 2024
Copy link
Contributor

Stale issue message

@zackarychapple
Copy link
Collaborator

bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants