如何在gulp 4中使用gulp.series?

问题描述 投票:0回答:1

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

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

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-appclean-tests都返回了我认为足够的流。

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

希望能够运行gulp all-tasks,以便在clean-tests成功完成后执行clean-app

gulp gulp-4
1个回答
0
投票

根据官方文件here尝试在你的任务中运行cb()

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'));
© www.soinside.com 2019 - 2024. All rights reserved.