Search code examples
cssgulpgulp-watch

How to Gulp-Watch Multiple files?


I have something like this:

gulp.task('default', ['css', 'browser-sync'] , function() {

    gulp.watch(['sass/**/*.scss', 'layouts/*.css'], function() {
        gulp.run('css');
    });

});

but it does not work, because it watches two directories, the sass and the layouts directory for changes.

How do I make it work, so that gulp watches anything that happens inside those directories?


Solution

  • gulp.task('default', ['css', 'browser-sync'] , function() {
    
        gulp.watch(['sass/**/*.scss', 'layouts/**/*.css'], ['css']);
    
    });
    

    sass/**/*.scss and layouts/**/*.css will watch every directory and subdirectory for any changes to .scssand .css files that change. If you want to change that to any file make the last bit *.*