bigskysoftware / idiomorph

A DOM-merging algorithm
BSD 2-Clause "Simplified" License
693 stars 33 forks source link

Distribute library as UMD and ES packages #12

Closed afcapel closed 9 months ago

afcapel commented 1 year ago

I'm interested in including idiomorph in another project that uses a JS bundler system but the current project distribution as an AMD module makes this a bit complicated.

To improve on this I've added a rollup build task that outputs different formats. At the moment it outputs a UMD and an ES modules and it drops the AMD module. AMD module popularity has declined significantly with the advent of other module systems, and providing UMD and ESM packages should cover all the cases. But let me know if that's not the case and we can add an AMD output as well.

With the new distribution files you can still use Idiomorph via a browser global by including the UMD module with a <script> tag, but you can also include it as an ES module and use in a project with a JS bundler, like esbuild, webpack, etc.

The htmx extension is also included as a UMD module so you can require it directly in a browser too

alexpetros commented 11 months ago

We went through this same discussion in htmx-land, and settled just changing the AMD wrapper to UMD, which was a far less invasive change that did not introduce a build step: https://github.com/bigskysoftware/htmx/pull/1263

I don't have strong feelings about idiomorph project management, just wanted to present an alternative option.

1cg commented 9 months ago

hey @afcapel this is too violent a change for me to bring in w/o really understanding it.

i'm willing to experiment a bit w/ this repo since it's relatively small though. i have heard good things about vite for stuff like this, what do you think?

1cg commented 9 months ago

@afcapel we now have support for CommonJS/UMD (thank you @rzane!) Is that "good enough" or do you want a full es module?

1cg commented 9 months ago

hear me out:

{ echo "let Idiomorph =(" && awk "/START FACTORY/{f=1;next} /END FACTORY/{f=0} f" src/idiomorph.js && echo ")(); export {Idiomorph}" } > dist/idiomorph.esm.js
1cg commented 9 months ago

OK, here's a slightly more radical change:

https://github.com/bigskysoftware/idiomorph/commit/6cc541f4fe1bd341b16003c6560d243928f00b91

Basically the idea is:

Simple and looks like it works. Does this work for people?

afcapel commented 9 months ago

@1cg that works for us, thanks! Love that you can get away without needing a JS bundler.

1cg commented 9 months ago

awesome, will cut a 0.3 release now