Gulp error: watch task has to be a function

后端 未结 5 989
花落未央
花落未央 2020-12-07 08:33

Here is my gulpfile:

// Modules & Plugins
var gulp = require(\'gulp\');
var concat = require(\'gulp-concat\');
var myth = require(\'gulp-myth\');
var ugl         


        
相关标签:
5条回答
  • 2020-12-07 08:40

    It worked for me in Gulp 4.0

    gulp.task('watch', function() {
          gulp.watch('src/images/*.png', gulp.series('images'));
          gulp.watch('src/js/*.js', gulp.series('js'));
          gulp.watch('src/scss/*.scss', gulp.series('css'));
          gulp.watch('src/html/*.html', gulp.series('html'));
    });
    
    0 讨论(0)
  • 2020-12-07 08:55

    In gulp 3.x you could just pass the name of a task to gulp.watch() like this:

    gulp.task('watch', function() {
      gulp.watch('app/css/*.css', ['styles']);
      gulp.watch('app/js/*.js', ['scripts']);
      gulp.watch('app/img/*', ['images']);
    });
    

    In gulp 4.x this is no longer the case. You have to pass a function. The customary way of doing this in gulp 4.x is to pass a gulp.series() invocation with only one task name. This returns a function that only executes the specified task:

    gulp.task('watch', function() {
      gulp.watch('app/css/*.css', gulp.series('styles'));
      gulp.watch('app/js/*.js', gulp.series('scripts'));
      gulp.watch('app/img/*', gulp.series('images'));
    });
    
    0 讨论(0)
  • 2020-12-07 09:00

    GULP-V4.0

    It is a bit late to answer this right now but still. I was stuck in this problem as well and this is how I got it working.

    In detail analysis what I was doing wrong

    1. I forgot to call the reload function when the watch noticed some changes in my html files.
    2. Since fireUp and KeepWatching are blocking. They need to be started in parallel rather than serially. So I used the parallel function in the variable run.
    0 讨论(0)
  • 2020-12-07 09:03

    thanks for all

    gulp.task('watch', function(){
        gulp.watch('app/sass/**/*.sass', gulp.series('sass'));
    });
    

    for version gulp 4.xx

    0 讨论(0)
  • 2020-12-07 09:05

    //Check what worked for me

    gulp.task('watch', function(){
        gulp.watch('css/shop.css', gulp.series(['shop']));
    });
    
    0 讨论(0)
提交回复
热议问题