'Best way to filter files in gulp.watch?
I would like to watch all, but the .min.ext files in my directories with gulp.js. What is the best way to filter out those?
Example:
gulp.task('watch', function(e) {
gulp.watch('./js/*.js', ['css']); // don't want to watch .min.js files. what is best way?
});
EDIT: If can't be done without external packages, which one is the most reputable?
Solution 1:[1]
gulp.watch
internally uses vinyl-fs
(see source), which uses gaze
, which uses itself minimatch
, so you should be able to ignore some files using !./js/*.min.*
.
In fact, this is even described in vinyl-fs's README:
fs.src(["./js/**/*.js", "!./js/vendor/*.js"])
[…]
Solution 2:[2]
Faced the same issue in gulp 4, the fix is as follows
gulp.task('watch', function() {
gulp.watch(['js/*.js','!js/*.min.js'], css);
});
css
is gulp.series
/gulp.parallel
or any function that you want to run.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Suraj Mandal |