Webpack promised based dynamic remotes and remote name uniqueness?

190 views Asked by At

I have a question about promise based dynamic remotes, as documented here:

https://webpack.js.org/concepts/module-federation/#promise-based-dynamic-remotes

In the example code, we see this:

return window.app1.init(arg)

I believe this attempting to call the init function off an object called app1, off the window global. I think app1 is added to the window object as a result of module federation, where the script tag is added to the document, which in turn calls out to 'http://localhost:3001/' + version + '/remoteEntry.js'. And that the code executes there adds app1 to the window object.

I imagine on the remote side, we'd see something like this in the webpack.config.js:

new ModuleFederationPlugin({
        name: "app1",
        filename: "remoteEntry.js",

Assuming the above is correct, then imagine that my consumer code is extended such that it tries to use promise based dynamic remotes from another module, at some other URL.

In that case, is it correct to assume the ModuleFederationPlugin's name on the second module must be something other than "app1"? In other words, does the name need to be unique across remotes that are acccessed? If not, how would the consumer of those remotes consume two different remotes that have the same name (and avoid conflicts on the window object)?

0

There are 0 answers