Don't bundle and minify your published npm packages - a podcast by Kent C. Dodds

from 2021-05-19T02:51:56

:: ::

https://twitter.com/kentcdodds/status/1394420201542668289?s=20
So the other day I tweeted about how I really want people to stop minifyingand bundling what they send to NPM. And just to clarify I it's fine if you
want to minify and bundle as one of the things you distribute as part ofyour package, but it shouldn't be the only thing and there are a couple of
reasons and what I do for my packages is I actually do have a UMD modulethat is bundled and I have a minified version of that as well.
So we have two of those and then I've got an ESM.R version which is like
fake ESM right now eventually I'll get around to making a native VSM
supported version. And then a common JS and those are the the four formatsthat I shipped to NPM. So the reason that I really really don't want people
to exclusively ship minified code is even with source maps can it can bereally difficult to debug and especially when we're talking about libraries
that I'm interacting with well even even transitive dependencies.
I like to be able to.Stick a console log in there or to step through with adebugger and it's just really difficult to do that if you've minified your
code and in particular what motivated me to tweet this in the first placewas I was working with a library that minified everything and it ended up
minifying its implementation of an abort signal and so the constructor namewas incorrect and node fetch actually checks the constructor name to know
if what you've passed is an abort signal which we could argue about whether
that's necessary or not, but the fact is that it does and becauseThey were
minifying it totally is unusable which is a less super annoying.So that's notification then on the bundling side of things this can get tobe a real problem like if for example your bundling a particular library
and I'm already using that library in my project MPM can't dedupe that and
do means it says, oh you're using this library in this other dependency
uses that library too.So we'll just have them both use the same files and therefore we don't have
to send.That code to the browser twice so we don't have to require that
code and evaluate it in person all that stuff. And so there are argumentsthat people make about bundling as like performance improvement so like you
could do that with some tools and and that could be useful but it couldalso be a big problem because then I can't like change the versions of the
things that I'm using and I don't have any control over that.
So there are a lot of issues there in general. So, please don't bundle
don't minify it's better this way. Let meDo that.

Further episodes of 3 Minutes with Kent

Further podcasts by Kent C. Dodds

Website of Kent C. Dodds