jamesRH
jamesRH

Reputation: 440

gulp watch is not always working

Sometimes gulp watch is not working when I save a javascript file. This is my watch task below.

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

I do have a bunch of sub directories. Would it be advisable to make my watch task be more specific like:

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

Upvotes: 0

Views: 2503

Answers (1)

joeyfb
joeyfb

Reputation: 3249

You need to make your task slightly more specific.

With './src/**/*.js' you are only watching javascript files in sub folders, not in the first level of ./src/

Having gulp.watch(['./src/**/*.js', './src/*.js'], ['js']) will work. Keep in mind watch can take an array of strings to watch for, don't call it multiple times.

Here's a similar question and answer:

How to Gulp-Watch Multiple files?

Upvotes: 1

Related Questions