module-federation / core

Module Federation is a concept that allows developers to share code and resources across multiple JavaScript applications
https://module-federation.io/
MIT License
1.41k stars 209 forks source link

Module Federation Plugin for Vite #2768

Open douglaszaltron opened 2 months ago

douglaszaltron commented 2 months ago

Clear and concise description of the problem

With the advent of @module-federation/esbuild, can we expect an official plugin to work with Vite? I say this because Vite has a large adoption. This would be wonderful for the module federation ecosystem.

Suggested solution

Today, for Vite, we have some options, but none integrated with the core of module federation, as the @module-federation/vite plugin still depends on @softarc/native-federation-esbuild.

Alternative

No response

Additional context

No response

Validations

zackarychapple commented 2 months ago

Happily this is something we can expect to see as "officially" supported. @yyx990803 has put this on the roadmap for Rolldown which is going to be the basis for the next version of Vite.

zhangHongEn commented 1 month ago

I am implementing this plugin, and I would like to ask here, how should I handle the first parameter of init and the shared of init, whether @module-federation/runtime should provide a merge api, or who can tell me how to do it, I am only one step away from completion

https://github.com/zhangHongEn/module-federation-vite/blob/9c3713ec24cb459f5f998ccb820c176cef65ae5c/packages/module-federation-vite/src/index.js#L48

zackarychapple commented 1 month ago

fantastic news @zhangHongEn! Will work on getting you answers asap.

@ScriptedAlchemy @zmzlois can we dig into this.

MadaraUchiha-314 commented 1 month ago

Can we just make this work with vite ? https://github.com/MadaraUchiha-314/rollup-plugin-module-federation

It already uses the runtime and the sdk and has solved most of the problems related to supporting MF 2.0

Happy to collaborate on this. @zhangHongEn

FYI, I have been collaborating with @ScriptedAlchemy on this for the past few months and it's almost close to completion

MadaraUchiha-314 commented 1 month ago

how should I handle the first parameter of init and the shared of init

https://github.com/MadaraUchiha-314/rollup-plugin-module-federation/blob/main/packages/rollup-plugin-module-federation/src/index.ts#L585

This is how you use the shareScope that's passed into init ^

zhangHongEn commented 1 month ago

how should I handle the first parameter of init and the shared of init

https://github.com/MadaraUchiha-314/rollup-plugin-module-federation/blob/main/packages/rollup-plugin-module-federation/src/index.ts#L585

This is how you use the shareScope that's passed into init ^

Thanks, this is very useful

I already support dev and build modes of vite, and have all the main features, but I haven't done other enhancements of 2.0, such as manifest.json and runtime plugins, etc. Can I PR here and then we can improve it together? https://github.com/module-federation/vite/issues/4

zmzlois commented 1 month ago

@zhangHongEn would love to check your PR and work on it together too

zhangHongEn commented 1 month ago

@zhangHongEn would love to check your PR and work on it together too

pr is here, it can speed up some progress