I'm trying to set up a gulp-watch which triggers a gulp task when some files change. For this purpose I'm using the following code:
gulp.task('watchChanges', function(cb){
console.log("Looking for file changes in " + watchPath+".");
return watch(watchPath, ['FilesChanged']);
});
gulp.task('FilesChanged', function (cb){
FilesChanged();
cb();
})
function FilesChanged()
{
console.log("Files changed:")
}
Whenever the files change I would like it if the 'FilesChanged' task would fire and I'd see the "Files changed:" text in console. This doesn't happen.
When I change my watchChanges task to this:
gulp.task('watchChanges', function(cb){
console.log("Looking for file changes in " + watchPath+".");
return watch(watchPath, FilesChanged);
});
Can anyone explain why the first piece of code does not execute correctly?
Since you are using gulp-watch if you look at its function definition:
you can see that it will take a callback function which is why your
works and
does not. gulp-watch will not take an array of tasks like gulp.watch will:
gulp-watch and gulp.watch are two entirely different things. What you probably want is
If you then to see which files are being processed, try one of the suggestions from get the current file name.