core
core copied to clipboard
runtimePlugins support pass parameters
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
- [X] Read the Contributing Guidelines.
- [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@ahabhgk What do you think about it ? Can we do it in rspack as well ?
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.
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;
}
}
}
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
Stale issue message
bump
Stale issue message