When there is no listening file in the gulp listening directory, the listening will be invalid.

  node.js, question

Problem

Sample code

gulp.task("sass", function () {
 return gulp.src("./Style/JS/**/*.scss")
 .pipe(sourcemaps.init())
 .pipe(sass({
 "outputStyle": "compressed"
 }).on("error", sass.logError))
 .pipe(autoprefixer({browsers: ['last 8 versions']}))
 //.pipe(minifyCss())
 .pipe(sourcemaps.write("./"))
 .pipe(gulp.dest("./Style/JS/"))
 });
 
 gulp.task("sass-watch",function(){
 gulp.watch("./Style/JS/**/*.scss", ["sass"]);
 });

describe

As in the above code, the watch task has monitored./Style/JS/Scss files under the directory, but when there are no scss files in the JS directory, the task is opened, and then the files are monitored afterwardsaddchangeEvents will not trigger.

How to solve this problem?

Use version

node: V4.2.4
gulp: V3.9.0

Reply answer

After testing, when the listening directory is an empty folder, even if the listening path is removed./insteadStyle/JS/**/*.scssThis problem will still occur.
At the same time also tested the use ofabsolute addressThis problem also occurs when listening for paths.

Gulp4.0watchEvent based onchokidarModule to fix this problem after upgrading Gulp to 4.0.