You are viewing...

One Way How Javascript Bundling is Stupidly Complex

Updated on October 08, 2020 at the 11th hour

DISCLAIMER: Expressed views on this blog are my own.

Anyone heard of any other language where there are "module" specs? You know specs for how your library will be bundled up in order to expose your library for consumption.

AMD, CJS, UMD, ESM, SystemJS, GGJS, HYZM and whatever acronyms out there

Why the fk do these things exist? Oh right, because Javascript left the idea of library importing out. It wasn't conceivable that people would need to do this in the browser until they did. I guess other language designers figured people share code and that company front end teams love to copy paste code. I don't know the history here, but I'm sure it has to do with 'no one needed it' or 'there is a sufficient external way to do it'.

These specs only add to complexity. When do I want to use AMD vs CJS? What if a library is bundled only in AMD? Do I look up a way to convert from AMD to CJS? What about ESM, can I use that on the front end or backend? UMD hmm.... AMD... fuck who cares. Why should I give two shits about module bundling? There are only two places to import: front and backend. There should be 1 default for each while all the others solve niche cases.

Some libraries choose to bundle in one or more specs, which to me is fucking weird, but understandable. Some don't understand the shit so they write all their source using one bundle spec. I'm not surprised why since it is never explained why there is a 'dist' vs 'src' folder in a Github repository. Some libraries put their umd/amd into the src folder. What am I supposed to review the source + the bundled output? Lot of weird shit out there because the 100 module definitions shit is unnecessary.

I default to CJS all the way because require which means typically exposing your public api via module.exports. ESM is new for the whole native import, export, default keywords. Let the bundler given a target (browser or nodejs) figure out how to go from CJS or ESM to what may be supported for lowest specified versions of browser or NodeJS.

Why should JS be complicated by all these other module specs? Shit is ridiculous.

I like JS, but things like this make me dislike it from time to time.

You just read "One Way How Javascript Bundling is Stupidly Complex". Please share if you liked it!
You can read more recent posts here.