Gulp 4 个迁移错误(您是否忘记发出异步完成信号?)

Gulp 4 Migration Errors (Did you forget to signal async completion?)

我有一个 gulp 3 文件,我正在尝试将其升级到 gulp 4。当我这样做时,一些任务可以工作,而其他任务则不能。我得到的三个错误如下:

干净的风格:

gulp.task('clean-styles', function (done) {
    var files = config.temp + '**/*.css';
    clean(files, done);
});

[23:47:05] The following tasks did not complete: clean-styles 
[23:47:05] Did you forget to signal async completion?

scss-观察者:

gulp.task('scss-watcher', function () {
    gulp.watch([config.scss], ['styles']);
});

[23:51:27] 'scss-watcher' errored after 2.46 ms
[23:51:27] Error: watching ./src/client/styles/styles.scss: watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)

样式:(如果我删除干净样式系列,这将起作用)

gulp.task('styles', gulp.series('clean-styles', function () {
log('Compiling SCSS --> CSS');

return gulp
    .src(config.scss)
    .pipe($.scss())
    .pipe($.autoprefixer({ browsers: ['last 2 versions', '> 5%'] }))
    .pipe(gulp.dest(config.temp));
}));

[23:52:42] The following tasks did not complete: styles, clean-styles
[23:52:42] Did you forget to signal async completion?

兽医:(有效)

gulp.task('vet', function () {
    log('Analyzing source with ESLint');
    return gulp
        .src(config.js)
        .pipe($.if(args.verbose, $.print()))
        .pipe($.eslint())
        .pipe($.eslint.format())
        .pipe($.eslint.failOnError());
});

函数:

function clean(path, done) {
    log('Cleaning: ' + $.util.colors.blue(path));
    del(path, done);
}

function log(msg) {
    if (typeof(msg) === 'object') {
        for (var item in msg) {
            if (msg.hasOwnProperty(item)) {
                $.util.log($.util.colors.blue(msg[item]));
            }
        }
    }
    else {
        $.util.log($.util.colors.blue(msg));
    }
}

我一定是漏掉了什么。任何人都可以补充我所缺少的吗?

干净风格

del 不接受回调函数。它 return 是一个 Promise,你必须 return 在你的任务中:

function clean(path) {
    log('Cleaning: ' + $.util.colors.blue(path));
    return del(path);
}
gulp.task('clean-styles', function () {
    var files = config.temp + '**/*.css';
    return clean(files);
});

scss-watcher

gulp.watch() 不再支持任务名称数组。你必须给它传递一个函数,gulp.series()gulp.parallel():

gulp.task('scss-watcher', function () {
    gulp.watch([config.scss], gulp.series('styles'));
});

样式

应该与上面 clean-styles 的更改一起工作。

朋友们,这是解决这个问题的方法:

我们需要调用回调函数(Task 和 Anonimous

function electronTask(callbackA)
{
    return gulp.series(myFirstTask, mySeccondTask, (callbackB) =>
    {
        callbackA();
        callbackB();
    });

}