Search code examples
gulpgulp-watch

Delay in gulp watch


Currently I'm working true ftp and running gulp watch on te server, now te problem is that when my gulp watch is detecting changes the file is not ready with uploading, so I need to have a delay in my gulp watch.

gulp.task('watch', function() {
  setTimeout(function() {
    gulp.watch(config.js.app.pathIn + '/**/*.js', ['js_app']);
    gulp.watch(config.js.vendor.pathIn + '/**/*.js', ['js_vendor']);
    gulp.watch(config.scss.pathIn + '/**/*.scss', ['scss']);
  }, 3000);
});

This is not delaying the rendering of the files, how can I make sure to have a delay when rending the files?


Solution

  • Gulp-wait looks like it could work for you. Insert it into the top of your three tasks.

    gulp.task('watch', function() {
       gulp.watch(config.js.app.pathIn + '/**/*.js', setTimeout(function() {
         gulp.start('scss')
      }, 3000)
    });
    

    Above might work if you want a setTimeout method but it uses gulp.start - to be removed from gulp4.0. Much easier if you used gulp4 and just made a function call here to your task instead of to gulp.start.

    But I suggest gulp-wait.