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:
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)?
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.
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.
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.
There are some ways that comes to my mind:
It's more about your package.json, so if you could optimize it, it's a very good option:
–production
flag on npm install).Use node-prune or modclean or other packages like these, to remove unnecessary files from node_modules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With