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.

Dynamic remoteEntry.js URL plugin

See original GitHub issue

Hi, I wrote a plugin to help solve the following two needs we had for module federation. I got the permission to open source it to help the community of module federation.

  • Dynamic URL, have the ability to define the URL at runtime instead of hard code at build time.
  • Cache invalidation. Append random query string to the end of the remoteentry.js to have better control of cache invalidation. For example, the getRandomString() below will generate the same random string in a 5 minutes window based on current epoch time.

Usage,

// webpack.config.js

plugins: [
    new ModuleFederationPlugin({
        name: 'my-app',
        remotes: {
            'my-remote-1': 'my-remote-1@[window.remote-1-domain]/remoteEntry.js?[getRandomString()]',
            ...
        },
        shared: {...}
    }),
    new ExternalTemplateRemotesPlugin(), //no parameter,
    ...otherPlugins,
]

Basically, this plugin modifies webpack generated code and transform the template string into a javascript expression, which it is able to read values from the global javascript context. Since module federation uses webpack external module, the plugin is applied to external module, not solely for module federation.

Here is the gist of the file. I use a gist instead of pasting here to have potential fixes.
https://gist.github.com/matthewma7/915b28846ad99d582e6b4ddea6dfc309

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:37
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

28reactions
ScriptedAlchemycommented, Jun 8, 2021

Plugin has been published to npm

22reactions
ScriptedAlchemycommented, May 18, 2021

Ill work on creating an npm package under module federation tomorrow @skyrex-mark

thanks @ksrb

Read more comments on GitHub >

github_iconTop Results From Across the Web

4 Ways to Use Dynamic Remotes in Module Federation
Luckily Webpack Module Federation supports dynamically defining URLs for our remote applications. We are going to consider four solutions ...
Read more >
Let's Dynamic Remote modules with ... - DEV Community ‍ ‍
Use ModuleFederationPlugin in your webpack.config.js of the app that you wish to consume modules. Pay attention that the remotes entry now ...
Read more >
Module Federation: remote url with slug possible in webpack ...
I'm looking to use a component from a remote application in my host application using module federation. Is it possible to dynamically change ......
Read more >
Dynamic Remotes, Webpack Module Federation - Hemanth.HM
The webpack module federation post resulted in many folks asking me if remote URLs need to be known at build-time?
Read more >
Module Federation - webpack
Ensure you have loaded the container before attempting to dynamically connect ... remotes: { app1: 'app1@http://localhost:3001/remoteEntry.js', }, }), ], };.
Read more >

github_iconTop Related Medium Post

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