0

I'm using gulp-watch plugin and would like to copy newly added files in the source to the target destination.

watch({glob:SOURCE + '/**/*.js'})
    .pipe(plumber())
    .pipe(gulp.dest(DESTINATION));

Every time a new file is added into the SOURCE directory I get "Bus error: 10" and the watch breaks without copying the newly added file.

Denzo
  • 431
  • 1
  • 4
  • 15

2 Answers2

0

Please you this syntax for adding new files in gulp

gulp.task('task_name', function() {
    return watch({
      glob: SOURCE
    }, function(files) {
      return files.pipe(plumber()).pipe(jade()).pipe(gulp.dest(DESTINATION));
    });
});
Amit Mourya
  • 538
  • 1
  • 7
  • 18
-1

gulp.watch doesn't create a source stream, it triggers on file changes and calls tasks.

Try creating a simple move task alongside a watch task, then trigger the move from the watch. Something like this:

gulp.task('move-js', function() {
  gulp.src('./js-src/**/*.js')
    .pipe(gulp.dest('./js-dest'));
});

gulp.task('watch-js', ['move-js'], function() {
  gulp.watch('./js-src/**/*.js', ['move-js']);
});

Note that the watch-js task has move-js as a dependency, this will call the move task whenever the watch is invoked, rather than waiting for something in the watched directory to change.

I repeated the glob for clarity, but that should probably be stored in a variable.

joemaller
  • 19,579
  • 7
  • 67
  • 84
  • I'm using gulp-watch plugin https://www.npmjs.org/package/gulp-watch not the bundled watch that comes with gulp. – Denzo Jul 07 '14 at 00:43