Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node_modules folder too large

I've been using Gulp for quite a while and either I didn't notice it took this much space from the beginning or the sizes have been growing.

I only use it for very normal front-end work. For example, this is the request part of my gulpfile.js:

var gulp         = require('gulp'),
    autoprefixer = require('gulp-autoprefixer'),
    browserSync  = require('browser-sync'),
    concat       = require('gulp-concat'),
    copy         = require('gulp-copy'),
    del          = require('del'),
    htmlmin      = require('gulp-htmlmin'),
    merge        = require('merge-stream'),
    streamqueue  = require('streamqueue'),
    cleancss     = require('gulp-clean-css'),
    gulpif       = require('gulp-if'),
    newer        = require('gulp-newer'),
    imgmin       = require('gulp-imagemin'),
    plumber      = require('gulp-plumber'),
    postcss      = require('gulp-postcss'),
    order        = require('gulp-order'),
    rename       = require('gulp-rename'),
    runSequence  = require('run-sequence'),
    sass         = require('gulp-sass'),
    sourcemaps   = require('gulp-sourcemaps'),
    uglify       = require('gulp-uglify'),
    uncss        = require('gulp-uncss');

Now, according to du -sh, node_modules weighs 2.2GB which I think is way too much. I wanted to dig a bit deeper so I looked all root modules:

DaisyDisk look at a regular node_modules/ folder


I'm probably being naive here but I'm just expecting some javascript functionality, I don't see how or why these modules, especially the top ones, can be so large in size.

Is this just how Gulp is designed? Am I doing it backwards? Can I improve this (besides not using it/those)?

like image 287
Neithan Max Avatar asked Feb 06 '17 01:02

Neithan Max


People also ask

Why is Nodemodules 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?

Using 'Git Bash' to remove the folder is the simplest way to remove all folders including subfolders in the 'node modules'. It will take a while to delete everything, but it works without any installation.

What happens if I delete node_modules?

Anybody can suggest if I delete node_modules folder and after re-creating it, will I get all the already installed packages back in the same way they were just before deleting? YES, you will get back all the packages listed in your package. json file.


1 Answers

There are some ways that comes to my mind:

  1. It's more about your package.json, so if you could optimize it, it's a very good option:

    • separate packages as devDependencies and dependencies, it helps to decrease the node_modules size in production mode (when you use the –production flag on npm install).
    • replace some libs that are big in size or having so many dependencies with lighter libs or libs with fewer dependencies.
  2. Use node-prune or modclean or other packages like these, to remove unnecessary files from node_modules.

like image 135
marzzy Avatar answered Sep 27 '22 18:09

marzzy