Best way to filter files in gulp.watch?

2019-01-30 22:24发布

问题:

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?

回答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"])
[…]


标签: node.js gulp