2

有一个超级简单的 gulp 文件,我想在其中一个接一个地运行一些基本的 gulp 任务。

我似乎无法在 Gulp v4 中运行它。在 Gulp v3 中使用run-sequence而不是类似的东西gulp.series()

const gulp = require("gulp");
const clean = require('gulp-clean');

gulp.task('clean-app', async () => {
  return (gulp.src('./dist/app', {read: true, allowEmpty: true})
    .pipe(clean()));
});


gulp.task('clean-tests', async () => {
  return ( gulp.src('./dist/tests', {read: true, allowEmpty: true})
    .pipe(clean()));
});

gulp.task('all-tasks', gulp.series('clean-app', 'clean-tests'));

各个 gulp 任务clean-appclean-tests单独运行良好。

但是,当我使用时gulp all-tasks出现以下错误

gulp all-tasks
[17:50:51] Using gulpfile ~\IdeaProjects\my-app\gulpfile.js
[17:50:51] Starting 'all-tasks'...
[17:50:51] Starting 'clean-app'...
[17:50:51] Finished 'clean-app' after 10 ms
[17:50:51] The following tasks did not complete: all-tasks
[17:50:51] Did you forget to signal async completion?

clean-app和返回clean-tests流,我认为就足够了。

尝试使用gulp4-run-sequence 但我得到了同样的错误。

希望能够在成功完成后执行gulp all-tasks这样的运行。clean-testsclean-app

4

1 回答 1

2

depending on the official documents here try to run cb() in your tasks like that

const gulp = require("gulp");
const clean = require('gulp-clean');

gulp.task('clean-app', (cb) => {
  gulp.src('./dist/app', {read: true, allowEmpty: true}).pipe(clean());
  cb();
});

gulp.task('clean-tests', (cb) => {
  gulp.src('./dist/tests', {read: true, allowEmpty: true}).pipe(clean());
  cb();
});

gulp.task('all-tasks', gulp.series('clean-app', 'clean-tests'));
于 2019-04-29T21:08:55.320 回答