Neithan Max
Neithan Max

Reputation: 11766

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

Upvotes: 25

Views: 18209

Answers (1)

marzzy
marzzy

Reputation: 788

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.

Upvotes: 5

Related Questions