一年之后 ...
使用
GazdebounceDelay
选项对我没有任何改变,我也不明白如何使用 gulp-batch 回调参数:/
......
为了避免在更改多个文件后连续调用任务,我使用了 oldschool setTimeout 函数:
// ...
var
SRC = ['js/*.js', '!js/*.min.js'], DEST = 'js',
processJs = function(){
util.log('Processing: ['+ SRC.join(' | ') +']');
var stream = gulp.src(SRC)
.pipe(uglify())
.pipe(concat('scripts.min.js'))
.pipe(gulp.dest(DEST));
return stream;
};
gulp.task('default', function(){
var delay = 2000, timer,
watcher = gulp.watch(
SRC,
// Callback triggered whatever the event type is (added / changed / deleted)
function(event) { // .path | .type
// If the timer was assigned a timeout id few time ago..
// Prevent last postpone task to be run
if(timer){
clearTimeout(timer);
}
// Postpone the task
timer = setTimeout(
function(){processJs();timer=0;}
,delay
);
}
);
util.log("/!\\ Watching job "+ Array(25).join('~'));
});