我有以下一饮而尽配置:这个gulp命令是否会等待依赖任务?
gulp.task('bar', function() {
return gulp.src(files, { base: './' })
.pipe(gulp.dest('dist'))
});
gulp.task('foo', ['bar'], function() {
// do something...
});
将foo
等待bar
完成,然后再运行?
我有以下一饮而尽配置:这个gulp命令是否会等待依赖任务?
gulp.task('bar', function() {
return gulp.src(files, { base: './' })
.pipe(gulp.dest('dist'))
});
gulp.task('foo', ['bar'], function() {
// do something...
});
将foo
等待bar
完成,然后再运行?
按照文档here:
要执行并完成之前,你的任务将运行任务的数组。
所以是的,它会在它运行任务之前完成。
此外,请注意以下说明。如果您的任务正在触发后台任务,并且没有正确返回,则gulp可能会错误地认为您的任务已完成。
注意:您的任务是否在依赖关系完成之前运行?确保您的依赖任务正确使用异步运行提示:接受回调或返回承诺或事件流。
除了评论和其他答案,我只想补充一点,你需要返回一个stream,一个承诺,或致电task function callback
parameter。
Gulp使用Orchestrator执行任务。
返回一个流(最常见的情况,并承诺类似)
gulp.task('somename', function(done) {
return gulp.src(res)
.pipe(minify())
.pipe(gulp.dest('build'));
});
使用回调(返回时,是不是一种选择)
gulp.task('somename', function(done) {
// async function which does not return a stream like other gulp functions
getFilesAsync(function(err, res) {
// pass any errors to the callback
if (err) return done(err);
var stream = gulp.src(res)
.pipe(minify())
.pipe(gulp.dest('build'))
.on('end', done); // use the callback when it's done
});
});
如果你不这样做的一个这些咕嘟咕嘟不会知道任务何时完成,并会立即开始下一个任务。
__是的,它会 – Satpal
它会在运行前等待,只要注意,如果你指定了多个依赖项,它们将全部并行运行,并不一定按照指定的顺序执行 –