module-federation / external-remotes-plugin

Dynamically set remote origins at runtime within hosts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Load window vars asynchronously

nkalinov opened this issue · comments

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.

And I dont think this plugin is really maintained anymore, the current recommendation is to use the "promise new promise" approach

Thanks, after a second look it does cover my needs, yeah.