originjs / vite-plugin-federation

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

React Webpack Host -> React Vite Remote #291

Open dykrupp opened 2 years ago

dykrupp commented 2 years ago

I've been trying to follow the 'vue3-demo-webpack-esm-esm' and apply a similar concept using a React Webpack5 host which consumers a remote exposed from Vite.

Is this supported when the host is using target: 'web' in the webpack.config?

Are there are relevant examples I'm missing here?

rchrdschfr commented 1 year ago

I'm also interested in the same setup and haven't got it to work yet.

Go1dExperience commented 1 year ago

Hi. When I use the same setup of webpack host and remote vite, I have an error: cannot use import.meta outside a module in remoteEntry.js. Have you run into the same situation? Was it because I didn't configure vite.config to the correct target, or is it because of my webpack.config? Please let me know and I will share my setup if you need.

AZReed commented 1 year ago

I have the same issue. No solution so far. In my case the error is the exact same as in this other issue https://github.com/originjs/vite-plugin-federation/issues/279. Any news on this?

Oterem commented 1 year ago

I'm mostly interested in dynamic load of a vite MF when the host is a react webpack5 UI

SQReder commented 1 year ago

bump this

taylous commented 1 year ago

i am also experiencing the same problem...

in webpack5 (ex cra, vue-cli), it was because of the splitChunk option, but vite doesn't seem to have that option.

adirzoari commented 9 months ago

@Oterem @SQReder @AZReed @rchrdschfr @taylous @dykrupp I looking the same, React with Webpack as Host and React with Vite as Remote. did you find a solution/an example?

SQReder commented 9 months ago

@adirzoari Still nope

vinodhum commented 7 months ago

+1, any update on this ?

emahnovets commented 6 months ago

+1

SQReder commented 5 months ago

Ok, I've got something. I'm too lazy to make reproduce repo, but following steps should guide you in the right direction:

1) Use full dynamic MF integration variant 2) To load the Vite MF create module script tag

<script type="module" src="http://somewhere/assets/remoteEntry.js"></script>

3) Dynamically import this module using the full URL. Take note of the webpackIgnore: true directive:

const container = await import(/* webpackIgnore: true */ "http://somewhere/assets/remoteEntry.js")

4) Proceed as usual

await container.init(__webpack_share_scopes__.default);
const factory = await container.get('./ExposedModule');
const module = factory(); // here is external exposed module

I hope you find this helpful