core icon indicating copy to clipboard operation
core copied to clipboard

runtimePlugins support pass parameters

Open 2heal1 opened this issue 1 year ago • 6 comments

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.

2heal1 avatar Jan 16 '24 08:01 2heal1

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

2heal1 avatar Jan 16 '24 09:01 2heal1

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.

ahabhgk avatar Jan 16 '24 09:01 ahabhgk

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;
     }
  }
}


2heal1 avatar Jan 16 '24 09:01 2heal1

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

ScriptedAlchemy avatar Jan 18 '24 07:01 ScriptedAlchemy

Stale issue message

github-actions[bot] avatar Mar 22 '24 15:03 github-actions[bot]

bump

zackarychapple avatar Mar 22 '24 17:03 zackarychapple

Stale issue message

github-actions[bot] avatar Jun 09 '24 15:06 github-actions[bot]