Search code examples
gulp-watch

How to disable gulp-watch to copy all files on start task


I have a gulp watch task like this:

gulp.src(devFiles, {base: gulpConfig.path.src})
  .pipe(watch(devFiles, {base: gulpConfig.path.src}))
  .pipe(gulp.dest(gulpConfig.path.public + "/"))

The task it's working ok with one problem: When I launch the task this will copy all files from source to destination. How can I disable this behaviour: the copy files I want to be a different task, and this one just to watch files for changes. In 99% the files are already there, so I don't need to copy again in destination folder.


Solution

  • I found this solution (inspired from gulp-watch docs):

    watch(devFiles, {base: gulpConfig.path.src, ignoreInitial: true, verbose: true}, function (obj) {
            gulp.src(obj.path, {base: gulpConfig.path.src})
                .pipe(gulpConfig.path.public + "/");
        });
    

    Where devFiles is an array of files masks, gulpConfig.path.src is source path, and gulpConfig.path.public is the destination folder. I'm using this code from 2 days and work very well. Now I didn't have to wait to finish loading all files on public folder at starting dev-watch task.