4
votes

So mine is a pretty simple gulp file.

const gulp = require("gulp");
const ap = require("gulp-autoprefixer");

function styles() {
  return gulp
    .src("./style.css")
    .pipe(ap("last 2 versions"))
    .pipe(gulp.dest("./dist"));
}

function watch() {
  gulp.watch("./style.css", styles);
}

exports.watch = watch;
exports.styles = styles;

exports.default = watch;

Running the styles task independently does produce the autoprefixed css.

The watch task however gets stuck on Starting 'watch'...

Can someone tell me what's wrong.

Gulp CLI Version: 2.0.1 Gulp Local Version: 4.0.0 Node: 10.15.0 OS: Windows 10 (WSL)

1
Try gulp.watch("./style.css", gulp.series(styles)); in your watch function. It "should" work without the series but doesn't seem to. - Mark
Note that your watch task will only run when the file changes. Do you mean that the styles task doesn't run when you alter and save the file? - TheDancingCode
gulp.series(styles)) doesn't work. - Saif Al Falah
@TheDancingCode, when the watch task is run, Gulp should tell me that it is watching the glob. Instead it is just stuck at "Starting 'watch'..." - Saif Al Falah
That is the normal behaviour. The styles task won't run when you start the watch task, but only when you change and save the style.css file. - TheDancingCode

1 Answers

1
votes

This might be an old question but I encountered the same issue when upgrading an old project from gulp 3 to gulp 4. I had a watcher that should start before a server spun up but I got stuck at Starting 'watch'...

I could fix it by passing a done callback to the watcher task and calling it after the watch command. This led the server to start after it gets noticed that the watcher went through, like so:

    gulp.task('serve', gulp.series(['task1', 'task2'], function (done) {
        gulp.watch(['src/**/*.js']);
        gulp.watch(['src/**/*.less']);
        done(); // <-- this one
    }));