Open Jameskmonger opened 8 years ago
Thanks for the idea! I must admit that I am new to node and npm. If minified...would it only be the minified code in the node_modules
folder?
Yeah, it would. Your code on GitHub would still be the unminified development code, but the code that users have in their node_modules folder will be minified
Can all of the dependencies be minified too? Or does that need to be done by each package owner?
It has to be done by the package owners but most owners distribute their minified package.
Fair enough. I do agree that this takes a long time to install! I wonder how much minifying will impact that. Though that rational is likely the problem in the first place :P
I will certainly keep this in mind. I wonder if there are any good articles on it.
@Jameskmonger there's several reasons I think this isn't worth it:
npm
downloads packages as tarballs. I bet tar + gzip achieves similar size reduction to minificationpollinate
if they occur. I think this is why I've never seen a package that's distributed with only minified code (though I've seen packages like bootstrap that are distributed with both minified and unminified code)@jedwards1211 Most packages I've seen are distributed over npm with only minified code - bugs that occur can then be investigated with the full code, but the majority of users never need to debug it at all. Could you point to some packages which don't slim down their distributions?
Huh, I'm surprised you say that, because I can't remember the last time I've seen a package like that. These popular packages are distributed with unminified code:
That's odd, I've just looked into how React does it (only one I had already installed for a project) and you're right. However I don't think that they're doing it in the best way.
npm is a distribution platform to distribute packages to be used as they are distributed. I think that if a user wants to then go on to debug a package, they are obviously free to clone the github repo, but I think the distributed package should be as small as possible to reduce the footprint.
npm is a distribution platform to distribute packages to be used as they are distributed
What do you mean by this? NPM isn't a CDN. And even on CDNs, most projects I've seen distribute non-minified code alongside minified code.
I know in the case of React, it's distributed with if (process.env.NODE_ENV !== 'production')
blocks containing dev helpers. When you use Webpack's DefinePlugin
to define process.env.NODE_ENV: '"production"'
, and use Webpack's UglifyJsPlugin
, it removes those blocks from the React code, which is all according to React's own advice.
If you're concerned about slow npm install
s, try using yarn
.
If you're worried that non-minified code will wind up in bundles you send to the client, don't rely on packages being distributed that way -- it's up to you to minify your client bundles.
If it's something else -- are non-minified packages causing you or someone else problems?
I agree that it would be cool to make this smaller. Though I also think that npm and the way it downloads a tree of dependencies will always be slow. Minifying may not really add gains in terms of install times when considering the deps. Those definitely need reducing though.
With this type of tool I'm not sure anyone will really need to edit the installed version. I'd really like it to become stable and not try to do too much. If this overall pattern gets distilled it would be cool to rewrite it in something like GO so that it really could just be a binary that you download quickly as part of a CI process.
The other thing about this is that (I assume at least) it's not really intended to be used as a dependency of anything else. I would be more concerned about pollinate
's size (and primarily try to trim down its dependencies) if it were bloating other downstream projects.
I've never actually come across any big issues with package size @jedwards1211 - I'm just aware that it could cause issues with people who have significantly slower connections (developing countries for example)
It could be better to minify the code as a prepublish npm command into a distribution folder (
dist
?) which is then included in thefiles
property ofpackage.json
, rather than the unminifiedlib
folder.This change could make a slight difference in the size of the distribution.