Load window vars asynchronously
nkalinov opened this issue · comments
Nikola Kalinov commented
Is there a way to set the window variables asynchronously after an AJAX call?
E.g.
// webpack.config
remotes: {
'remote': 'remote@[window.remoteUrl]'
}
// index.js
async function setup() {
try {
const manifest = await fetch(`/apps/manifest.json`).then(res =>
res.json()
);
// Setup MFE URL after the call
window.remoteUrl = 'whatever';
} catch (e) {
console.error(e);
}
}
setup().then(() => import('./bootstrap'));
This do not work (just empty page) where if I set the var outside of setup()
it works.
einarq commented
I think this covers it?
https://webpack.js.org/concepts/module-federation/#promise-based-dynamic-remotes
einarq commented
And I dont think this plugin is really maintained anymore, the current recommendation is to use the "promise new promise" approach
Nikola Kalinov commented
Thanks, after a second look it does cover my needs, yeah.