How to get Gulp v4 watch observe file changes?

377 Views Asked by At

Here is a very minimalistic example gulpfile.js:

var gulp = require('gulp');
function foo(done) {
    console.log('change');
    done();
}
function watchFiles() {
    console.log('starting watching...');
    gulp.watch('./gulpfile.js', gulp.series(foo));
};
gulp.task('watch-files', gulp.series(watchFiles));

A message "change" should be displayed on the console every time, when the gulpfile.js itself gets edited. But it doesn't work. I get the initial message "starting watching..." and the Gulp info about starting the task displayed.

$ gulp watch-files
[[[00:07:48] Using gulpfile /var/www/.../my-app/gulpfile.js
[00:07:48] Starting 'watch-files'...
[00:07:48] Starting 'watchFiles'...
starting watching...

But changes on the defined file to be observed (the gulpfile.js) are ignored, so no further messages are being displayed.

What causes the issue and how to fix it and get the watching working?

0

There are 0 best solutions below