Npm Overhead - How To Deal With It?

When installing anything through npm, it downloads dozens of junk files. Usually I am looking for the final assembly of the library, the *.min.js file or something like that, but the rest is useless.

How do you handle all these useless files? Delete them manually or create the final application using any build tool like gulp or grunt ?

I am very confused since I have many npm modules installed in my webapp and the folder size is about 50 megabytes, but can only be 2 MB.

+7
javascript npm gruntjs gulp npm-install
source share
2 answers

npm install --production

Just installing npm installs both development and runtime dependencies. You can also install ENV for worldwide production for the server: npm config set production .

See this github issue. Please note that this will not only give you the final thumbnail, the assembly of everything, but will significantly reduce bloating. For example, a library may rely on babel-cli, babel-preset-es2015 and uglifyjs to be built (devDependency), but you don't need any of this if it also includes a pre-mined file.

+3
source share

Package management

For third-party packages not intended for development, I prefer Bower . It supports a smaller and no smaller version of your packages.

Build tool

Use Gulp or Grunt , Gulp would be my tool of choice.

Gulp task that will greatly improve your code:

  • minimizing both css and js
  • image optimization / compression
  • concatenation and caching to reduce server calls
  • batch versioning
  • automatic nesting of project dependencies
  • automatic nesting of external dependencies
  • static analysis of js and css
  • automatic build code changes
  • Deployment
  • Testing

Node

If you can, leave all your development tools in node and leave all your release plugins. Most node packages that are used in released applications have a parallel installation for installing assemblies.

Edit


Do not manually remove anything from node, as you do not know which packages have other packages as dependencies. If you are afraid that you have unwanted information, use npm rimraf to delete the node_modules folder, and then run npm install. The most important thing is to check your .json package for unnecessary saved packages.

+1
source share

All Articles