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

How to deal with libraries that aren't exported as UMD? #139

Closed Darksoulsong closed 2 years ago

Darksoulsong commented 2 years ago

I'm doing some testing with MFEs, and I've created a framework with 3 apps.



These MFEs share some libraries, so I added them to the "externals" array in webpack.config and included them in the "importMaps" of the root config. 

I'm getting an error because these libraries are not in UMD format, like Zustand for example (https://unpkg.com/browse/zustand@3.6.8/);



There's a comment in the index.ejs file about the accepted formats (UMD, Global variable or registered via System.register). Would you provide us with an example on how this can be done, please? Of course, I could ask to the Zustand devs to add a UMD version to the repo, but there are a couple libs with this same issue - so it makes sense to deal with it dynamically using SystemJS.

 

 

Any help would be great!

filoxo commented 2 years ago

If the library does not provide the right formats, someone needs to. Oftentimes this can also be found by searching for a project's "CDN version". Other possibilities are to look at repackaging the library yourself under @esm-bundle (explainer article here), or check if you can find a repackaged version at jspm.

Lastly, it appears Zustand exports UMD and System versions as of version 3.6.9.