我有以下的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
完成吗?
callback
参数。
Gulp使用Orchestrator来处理任务。
返回流(最常见的情况,类似于Promise)
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
});
});
done
大概是多余的吧? - Ben Astondone
回调函数的作用是表明它始终可用,即使你不使用它也是如此。是的,正如文档和其他答案中提到的那样,返回Promise将起作用。 - Emile Bergeron