How to make complete production build without http://localhost:3001/remoteEntry.js in production main.js?

CRA based for example: https://github.com/module-federation/module-federation-examples/tree/master/cra

Use promise new promise to change remote url at runtime or use env vars
Young technology =) this code works, but final static build does not work correctly without external magic. @ScriptedAlchemy Could you please, add to this example best way to get final build (ready to be hosted by NGINX, for example) in your opinion.
const isDev = !!process.env.NODE_ENV ? process.env.NODE_ENV === 'development' : true
const PUBLIC_PATH_1 = process.env.PUBLIC_PATH_1 || 'remote/'
const plugins = []
// ...
plugins.push(new ModuleFederationPlugin({
name: "host", // consumer
filename: "remoteEntry.js",
remotes: {
'remote': isDev
? 'remote@http://localhost:3001/remoteEntry.js'
: `promise new Promise(resolve => {
const thisScript = document.currentScript;
thisScript.src = './${PUBLIC_PATH_1}main.js';
})`,
},
exposes: {},
shared: {
...deps,
react: {
singleton: true,
requiredVersion: deps.react,
},
"react-dom": {
singleton: true,
requiredVersion: deps["react-dom"],
},
},
}))
I've manage that using '.env'. You cant take a look at the project example i've made here At my config i use env properties and they are replace by the wepack itself according with the build, dev or prod
Does anyone have a good approach on getting the URLs for different environments during runtime? My approach is to build a production image once and reuse it for every different environment in openshift with different configurations injected at deploy time instead of building different images for each environment.
promise new Promise is the best syntax for it since you can read and inject any remote from any location that you please.
you can also expose and set public path at runtime via a webpack runtime global. If you search my repo i also have a external remote plugin that reads values off the window or something else as you need.
i've seen promise new promise recommended in quite a few issues. is it worth adding a real world example on how this is done in a real world applications that supports multiple stages (dev, beta, prod, etc...)? curious on best practices around this.
Would be worth doing so but Its usually too much effort to actually build out a deployable example of that mechanism.
How I have it configured is usually a multi stage fallback approach. So pass a remote@url then have a parser that loops over the strings and generates a promise new promise variant where it looks for a window.remoteNameOverride || cookie.get(renoteNameOverride) || detectStageAndRewrite || use the original @ url that was passed to the plugin to begin with.
Now I can read location.href and point to stage if im in stage and there's no configuration to override it, and if im in prod it'll do the same. But at any point on any machine - I can still swap out the remote webpack will inject.
You could also point to an api or json and fetch() the config for the current host
@ScriptedAlchemy interesting approach! Curious if you have a sample gist? I’m trying to get a similar approach working with the dynamic-system-host example since I have like 15 remotes (with many more upcoming) and I don’t want to have dozens of remoteEntry calls at all startup.
I don't have a gist but use promise new promise and you can write the logic. I'll get around to an example at some point since I'll be implementing this exact capabilities for work. Since we have many codebases on different envs, QA needs a way to change the graph at will