【问题标题】:Problem with gulp watch after upgrading to gulp 4升级到 gulp 4 后 gulp watch 出现问题
【发布时间】:2020-05-24 09:28:41
【问题描述】:

链接到这个问题 = Gulp error: The following tasks did not complete: Did you forget to signal async completion?

当我尝试使用以下代码运行“watch”时,它会出错:

gulp.task('watch', async function() {
    var watchJs = gulp.watch(paths.js, ['scripts']),
        watchJson = gulp.watch(paths.json, ['json']),
        watchHtml = gulp.watch(paths.html, ['html']),
        watchCss = gulp.watch(paths.css, ['css']),
        watchFonts = gulp.watch(paths.fonts, ['fonts']),
        watchAssets = gulp.watch(paths.assets, ['assets']),

        onChanged = function(event) {
            console.log('File ' + event.path + ' was ' + event.type + '. Running tasks...');
        }

    watchJs.on('change', onChanged);
    watchJson.on('change', onChanged);
    watchHtml.on('change', onChanged);
    watchCss.on('change', onChanged);
    watchFonts.on('change', onChanged);
    watchAssets.on('change', onChanged);
});

错误提示:Error: watching src/js/**/*.js: watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)

但我不知道如何解决这个问题。我尝试将异步放在 gulp.task('watch', async function() { 但这不起作用

【问题讨论】:

    标签: gulp gulp-watch


    【解决方案1】:

    改变

     var watchJs = gulp.watch(paths.js, ['scripts']),  // gulp v3 syntax
    

     var watchJs = gulp.watch(paths.js, gulp.serie('scripts')),  //  gulp v4 syntax
    

    和你的其他人一样。查找从 gulp v3 到 v4 的迁移指南。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-05
      • 2018-08-14
      • 2019-07-28
      • 1970-01-01
      相关资源
      最近更新 更多