originjs / vite-plugin-federation

Module Federation for vite & rollup
Other
2.42k stars 243 forks source link

Load remote files from script and window (Dynamic Remote Containers) #244

Open itschip opened 2 years ago

itschip commented 2 years ago

Is your feature request related to a problem? Please describe.

Yes, in Webpack you can do this

      await loadScript(url, scope, module);

      //@ts-ignore
      await __webpack_init_sharing__('default');
      const container = window[scope];

      //@ts-ignore
      await container.init(__webpack_share_scopes__.default);
      const factory = await window[scope].get(module);
      const Module = factory();

      const appConfig = Module.default();

which allows you grab any exposed files from any remotes.

Describe the solution you'd like

A similar solution for this plugin/vite. Since we're not exposing a default exported React component, the lazy solution won't work for us. We are actually exposing a default exported object.

Describe alternatives you've considered

I have not yet.

Additional context

..

itschip commented 2 years ago

Had a new look at the README, and ofc found this

 remotes: {
    // 'remote module name': 'remote module entry file address'
    'remote-simple': 'http://localhost:5011/remoteEntry.js',
}

Could work, but since we need this in runtime, it's still a dead end I guess.

itschip commented 2 years ago

You can see a more detailed implementation of this here: https://github.com/project-error/npwd/blob/master/apps/phone/src/common/hooks/useExternalApps.tsx

yangjocy commented 2 years ago

Any update on this? We have same requirement here.

itschip commented 2 years ago

@yangjocy I've started to look into writing/propose a solution. I'll update this thread if I get anywhere with it.

ivankorobchuk123 commented 2 years ago

Any update on this? We have same requirement here.

guillerp8 commented 1 year ago

Any new here?

mostafa-raafat commented 1 year ago

@itschip any update?

itschip commented 1 year ago

@mostafa-raafat stil trying. A lot of this is still very dark magic to me.

ducan-ne commented 1 year ago

Waiting for this 🙌

ducan-ne commented 1 year ago

Oh it seems easier than I think I think I'll pick this as a workaround, but not sure if it gets any weird issue...

CleanShot 2023-04-09 at 23 38 37@2x