Dynamic remoteEntry.js URL plugin
See original GitHub issueHi, 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:
- Created 3 years ago
- Reactions:37
- Comments:18 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Plugin has been published to npm
Ill work on creating an npm package under module federation tomorrow @skyrex-mark
thanks @ksrb