question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compute `ModuleFederationPlugin`s remotes' URLs in the runtime

See original GitHub issue

With the remotes property we define where to pull remotes from:

remotes: {
  widget: `widget@http://localhost:3001/remoteEntry.js`,
},

It is possible to alternate the URL during the build

remotes: {
  widget: `widget@${isDev ? 'http://localhost:3001' : '/apps/widgets'}/remoteEntry.js`,
},

Though it seems like there is no way to define the remote’s URL dynamically in runtime.

I would imagine it like this:

remotes: {
  widget: () => {
    const prefix = location.host.startsWith('eu.') ? 'europe' : 'us';
    return `widget@${prefix}/apps/widgets/remoteEntry.js`
  },
},

It would be really useful to have such an option.

_Originally posted by @jazzfog in https://github.com/webpack/webpack/discussions/12213_

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
jazzfogcommented, Mar 27, 2021

Still think it’d be a useful feature.

0reactions
vankopcommented, Jun 21, 2022

remotes basically are external modules, you can use promise external see webpack test case for that https://github.com/webpack/webpack/blob/main/test/configCases/container/circular/webpack.config.js


so for dynamic externals please use promise

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module Federation: remote url with slug possible in webpack ...
Is it possible to dynamically change the remote url in the webpack.config file to include slugs which can change during runtime? Webpack config ......
Read more >
Module Federation - webpack
ModuleFederationPlugin combines ContainerPlugin and ContainerReferencePlugin . ... Generally, remotes are configured using URL's like in this example:
Read more >
Tutorial - A Guide to Module Federation for Enterprise
new ModuleFederationPlugin({ remotes: { FormApp: ... If a remote app URL changes, teams must remember to change both the remote app and host ......
Read more >
Webpack 5 Module Federation — Stitching two simple ...
Sharing code between themselves at runtime. ... execution for a moment to let the Webpack runtime interface with any remotes and comprehends ...
Read more >
4 Ways to Use Dynamic Remotes in Module Federation
It allows us to resolve the URLs at runtime using templating: plugins: [. new ModuleFederationPlugin({. name: "Host",. remotes: {.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found