developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8k stars 361 forks source link

[Probable user error] UMD builds no longer loading external dependency correctly #995

Closed aholachek closed 1 year ago

aholachek commented 1 year ago

Hi, thank you very much for this incredibly useful tool.

I use it to build my animation library react-flip-toolkit, but I believe I am doing something incorrect regarding UMD builds, and I was hoping I could get some guidance here.

The problem

Other than React libs, react-flip-toolkit depends on a single external library called Rematrix.

I've been using this codepen to verify that umd builds are working (clicking on the text should show an animation if everything is correct), however, at some point the external dependency Rematrix stopped loading correctly:

Screen Shot 2022-09-03 at 11 22 23 AM.

This configuration of script loading used to work for the pen: Screen Shot 2022-09-03 at 11 23 58 AM

Calls to Microbundle

I call microbundle here (for bundling react-flip-tooklit) as well as here (for bundling the underlying utility flip-toolkit).

Can you see anything I am doing wrong?

rschristian commented 1 year ago

You're missing --globals rematrix=Rematrix in flip-toolkit's build script.

While you do set that on react-flip-toolkit, it does no good as that does not rely on rematrix. Instead, it's flip-toolkit that has the dependency & will need to be made aware of what the global value is (Rematrix). It's the underlying utility that's tripping up, as your errors show.

aholachek commented 1 year ago

Thank you so much for the help, I just published a new version with your updates and indeed everything is working well now.

rschristian commented 1 year ago

Glad to hear it!