-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gulp is sometimes slow to start #632
Comments
gulpfile? node version? OS? |
First guess: too many dependencies being loaded on start is taxing the fs? Solution: lazily load plugins and deps in each task instead of at the top of the file |
Updated ;) What do you think so? |
It's certainly the loading of tasks/dependencies which is slow, but how to do it better? my code isn't correct there? it doesn't lazyload 'em? |
To lazyload, this var gulp = require('gulp')
var es = require('event-stream')
var gutil = require('gulp-util')
var imagemin = require('gulp-imagemin')
var svgmin = require('gulp-svgmin')
module.exports = function() {
var bitmap = gulp.src('src/frontend/images/**/{*.png,*.gif,*.jpg,*.jpeg}')
.pipe( gutil.env.dist ? imagemin( { optimizationLevel: 5 } ) : gutil.noop() )
var vector = gulp.src('src/frontend/images/**/*.svg')
.pipe( gutil.env.dist ? svgmin() : gutil.noop() )
return es.merge( bitmap, vector).pipe( gulp.dest('web/assets/images') )
} would become this module.exports = function() {
var gulp = require('gulp')
var es = require('event-stream')
var gutil = require('gulp-util')
var imagemin = require('gulp-imagemin')
var svgmin = require('gulp-svgmin')
var bitmap = gulp.src('src/frontend/images/**/{*.png,*.gif,*.jpg,*.jpeg}')
.pipe( gutil.env.dist ? imagemin( { optimizationLevel: 5 } ) : gutil.noop() )
var vector = gulp.src('src/frontend/images/**/*.svg')
.pipe( gutil.env.dist ? svgmin() : gutil.noop() )
return es.merge( bitmap, vector).pipe( gulp.dest('web/assets/images') )
} |
Also I would recommend using gulp-if instead of the |
You could also lazy require the gulp plugins so they're only required on first use. |
Thank you, I'll try all your advice. ;) |
After some tests, I must admit on a whole compilation, it changes not really (but it was premeditated). Instead of taking lots of time to start, gulp takes some times on each task. |
@kud you can use time-require to figure out which require is the slowest. But the require mechanism is expensive, especially on non-SSD harddrives. |
grazie mille ;) |
Interesting:
|
Lol, there's something really wrong with your computer. It seems like everything takes 60x the time it should.
On my computer:
|
Outside the scope of gulp, your computer is loading modules really slow. Closing. |
I think I've found the problem. As loading gulp modules ask lots of require, it does some I/O, and as I'm swapping at the same time, the hard disk hurts a lot. :) |
On my machine with lots of softwares (sketch, firefox as frontend dev, VMs, etc), I don't have enough ram for gulp and its start is in this case really slow.
Once it was started, all is ok, the compilation is really fast and the next time I start gulp, it'll be fast too.
Note : This issue is for the moment a memo, I'll be back with more information. ;)
An indication of a compilation without troubles:
Packages:
gulpfile.js:
node :
v0.10.31
macosx :
10.9.4
An example of task:
The text was updated successfully, but these errors were encountered: