Search code examples
gulpgulp-watch

Excluding subdirectory from gulp-watch throwing type error


I'm running the following watch task:

gulp.task('watch', function() {

    gulp.watch('./ui/scss/*.scss', ['styles']);
    gulp.watch('./js/*.js', '!./js/vendor/*.js', ['scripts']);
    gulp.watch('./**/*.html', ['html']);

});

But it seems to throw the following error?...

TypeError: Cannot assign to read only property 'mark' of !./js/vendor/*.js at new Gaze

Solution

  • You need brackets around the paths if you want to specify multiple. Try the following for your second watch:

    gulp.watch(['./js/*.js', '!./js/vendor/*.js'], ['scripts']);
    

    gulp.watch handles the file argument the same as vinyl-fs. So you can use all the features specified in their documentation in gulp.watch as well.