0

I tried with gulp.watch and watch (gulp-watch) but when i add the new file, dont copy in dest.

How i can to do this?

Thnks!

PD: I use version 3.9.1

gulp.task('default', function () {
  for(var i = 0; i < origen_web.length ; i++) {
    var source = '../..' + '/dir' + '/**/*';
    var dist   = '../../dist';

    watch(source, function(obj){
      copyFiles(obj, source, dist);
    });
  }
}

function copyFiles(source, dist, obj) {

  gulp.src(source)
  .pipe(gulp.dest(dist));
}

Sorry, this is my code more and less.

Cynth S.B.
  • 33
  • 3

2 Answers2

0

Ok, try with this.

gulp.task('default', function () {
  for(var i = 0; i < origen_web.length ; i++) {
    var source = '../..' + '/dir' + '/**/*';
    var dist   = '../../dist';

    watch(source, function(obj){
      copyFiles(obj, source, dist);
    });
  }
}

function copyFiles(source, dist, obj) {

  return gulp.src(source) // <-- here you force gulp to return the value
  .pipe(gulp.dest(dist))
  .pipe(notify({message: "This message is triggered if the data has been transferred"}));
}
mutantkeyboard
  • 1,614
  • 1
  • 16
  • 44
-1

Use absolute path to directories.

Duplicate question of Gulps gulp.watch not triggered for new or deleted files?

Lukas Liesis
  • 24,652
  • 10
  • 111
  • 109
  • Yep, I use this example but work if its copy all folder, if I copy file for file changed, dont work with new files :S – Cynth S.B. Oct 20 '17 at 07:21
  • Does it throw anything? Maybe script doesn't have permission to those files? Can you just use nodejs fs APIs to copy the file just to check? https://nodejs.org/api/fs.html – Lukas Liesis Oct 20 '17 at 07:26
  • I posted a little code and yep, I have permission because this files (add) is in the same folder that the copied files. – Cynth S.B. Oct 20 '17 at 07:37
  • This is old info that gulp.watch does not work on new or deleted files, see the duplicate question. No need for gulp-watch. – Mark Oct 20 '17 at 11:33