howardroark / pollinate

Template your base files and generate new projects from Git(Hub).
The Unlicense
225 stars 16 forks source link

Potential size reduction for npm distribution #19

Open Jameskmonger opened 8 years ago

Jameskmonger commented 8 years ago

It could be better to minify the code as a prepublish npm command into a distribution folder (dist?) which is then included in the files property of package.json, rather than the unminified lib folder.

This change could make a slight difference in the size of the distribution.

howardroark commented 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?

Jameskmonger commented 8 years ago

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

howardroark commented 8 years ago

Can all of the dependencies be minified too? Or does that need to be done by each package owner?

Jameskmonger commented 8 years ago

It has to be done by the package owners but most owners distribute their minified package.

howardroark commented 8 years ago

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.

jedwards1211 commented 7 years ago

@Jameskmonger there's several reasons I think this isn't worth it:

Jameskmonger commented 7 years ago

@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?

jedwards1211 commented 7 years ago

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:

Jameskmonger commented 7 years ago

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.

jedwards1211 commented 7 years ago

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 installs, 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?

howardroark commented 7 years ago

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.

jedwards1211 commented 7 years ago

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.

Jameskmonger commented 7 years ago

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)