single-spa / single-spa-react

Single-spa lifecycles helper for React applications
https://single-spa.js.org/docs/ecosystem-react.html
MIT License
227 stars 63 forks source link

Vite support? #209

Closed franmc01 closed 2 months ago

franmc01 commented 8 months ago

This plugin only works for CRA or can it be applied to vite react projects?

webJose commented 6 months ago

This plug-in is not dependant on the bundler you choose. Works with webpack, vite, rollup and probably all other bundlers. If you have an issue, you should describe it here, or in the Slack channel for single-spa.

franmc01 commented 6 months ago

Yes, I want to set up a platform where I want to take advantage of Single SPA and take advantage of the advantages and "agility" of Vite, but in the doc I don't see something with its own support, like an own plugin as in Native Federation. I have nothing against webpack, I know that in these issues is the father of the chicks since he started with module federation.

webJose commented 6 months ago

I see, but you're asking in the wrong repository. This repository is for a package that wraps a React component into a single-spa lifecycle object. That's it. Regardless of bundler, that's the job for this guy. All you have to do is tell your bundler to consider whatever file you made that exports the single-spa lifecycle object an "input" file. Then the bundler will works its magic and spit out bundled code whose origin is that file you created. This is, as far as I can tell, how every bundler works.

Now, you might be asking if there are tools for Vite. For that, visit the Vite Ecosystem page in the docs.

I personally recommend you the use of vite-plugin-single-spa, which is a plug-in I created. It is very opinionated, though, so be sure to read the documentation before you embark into using it. If you decide to use it, though, it takes almost all complications of single-spa off your hands, including CSS mounting and unmounting.

MilanKovacic commented 2 months ago

As José replied, you can either use the Vite plugin, or a custom solution. Single-spa is bundler-agnostic.