Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce the size of node_modules folder

Tags:

npm

angular

I have done Angular 2 application using npm, when the app has just 1 mb size, the node_modules folder consumes around 90 mb,so Is there any possibility to reduce the node_modules folder size, at least while publishing in IIS?

like image 207
Sridhar Paiya Avatar asked Apr 26 '16 09:04

Sridhar Paiya


People also ask

How do I reduce node modules?

We can reduce our node modules size by these actions: find and remove all unused dependencies with depcheck. deduplicate all the duplicated dependencies with yarn-deduplicate.

Why node modules are so big?

Originally Answered: Why are node_modules so large? The module structure used to be completely nested, meaning multiple versions of the same modules could be nested within each other. This is no longer the case, so module sizes are not as big as they used to be.

Can I delete the node_modules folder?

npx allows to run npm commands without installing the package. and then you can just run npkill from any directory to delete the node_modules folder. Once the list is displayed, you can navigate using arrow keys and delete the specific node_modules directory by hitting the spacebar.

Can I delete node_modules and reinstall?

You could remove your node_modules/ folder and then reinstall the dependencies from package. json. This would erase all installed packages in the current folder and only install the dependencies from package.


1 Answers

I would suggest using grunt-package-minifier

Initially I strip all the package.json, README etc. from node_modules but keep the essential JavaScript files in a structure that can be used by a CommonJS module loader.

Also have a look at reduce-node-modules-bloat.md

Hope this helps

like image 148
Bhushan Gadekar Avatar answered Oct 06 '22 05:10

Bhushan Gadekar