Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential size reduction for npm distribution #19

Open
Jameskmonger opened this issue Feb 24, 2016 · 13 comments
Open

Potential size reduction for npm distribution #19

Jameskmonger opened this issue Feb 24, 2016 · 13 comments

Comments

@Jameskmonger
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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

@Jameskmonger
Copy link
Author

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

@howardroark
Copy link
Owner

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
Copy link
Collaborator

jedwards1211 commented Feb 24, 2017

@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 minification
  • the amount of code in this package is probably pretty insignificant compared to the size of all its dependencies combined. Since minification would only affect the size of this package, it probably wouldn't make much of a difference.
  • It makes it harder for users to track down bugs in pollinate 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)

@Jameskmonger
Copy link
Author

@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
Copy link
Collaborator

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:

  • npm's own package
  • react
  • redux
  • react-redux
  • babel-core
  • core-js
  • eslint
  • redis
  • webpack
  • lodash

@Jameskmonger
Copy link
Author

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
Copy link
Collaborator

jedwards1211 commented Feb 24, 2017

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
Copy link
Owner

howardroark commented Feb 25, 2017

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
Copy link
Collaborator

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
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants