Sort of. It's a common practice from the days before module bundlers, where you would directly use the dependency in the browser via a `<script>` tag (or maybe concatenate it with grunt or whatever) and the size matters. Some folks still do this sort of thing via https://unpkg.com/. I think the closest thing to a "standard practice" is to ship a minified version for browsers and an unminified version for servers/module bundlers.
Many libraries published to npm are using some form of source transform like babel or typescript or flow, etc.
So for people to actually consume that module by source they need their own build process to do those same transforms, and then you'd need to have this be selective per every external module because no one build process is going to work for everything.
So generally you consume something that's been compiled and wrapped in UMD
I agree with this question. If I were to check the source code of every dependency in my node_modules and use a lock file, it would be great if I could feel confidant that this is the code I'm executing.
Having to read minified code to review dependencies is, well, stupid. This feel like a flaw in npm. I would prefer if npm never used minified code, but the source code instead. If that's not possible because of backwards compatibility, adding a flag like --no-minified could probably solve it.
That would be pretty hard for npm to enforce -- minified javascript is just javascript with short variable names, no extraneous whitespace, etc. Who's npm to say whether e.g. a function with a 1-letter name is there because the code is minified, or just there because that's what someone happened to write?
Yes, you're right, that's not possible. What I was thinking about was that there shouldn't be a difference between the code on github and the code published to npm. In that case the minified code should be uploaded to github, so that anyone that reviews the code on github should see the minified code. That's totally fine. The problem is that it's totally fine to upload something else to npm then github (minified code for instance).
There's a difference between minification and variable mangling. Generally they are done together, but you can minify javascript without mangling, or mangle without minifying.
16
u/samjmckenzie Nov 27 '18
Why are minified libraries published onto npm? Is this standard practice?