Best way to filter files in gulp.watch?

node.jsGulp

node.js Problem Overview


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?

node.js Solutions


Solution 1 - node.js

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 - node.js

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questioni--View Question on Stackoverflow
Solution 1 - node.jsPaul MougelView Answer on Stackoverflow
Solution 2 - node.jsSuraj MandalView Answer on Stackoverflow