只是一个简单的问题来阐明 gulp 任务中的参数"done"
做什么?
我明白了,这是任务函数中的回调,如下所示。
gulp.task('clean', function(done) {
// so some stuff
creategulptask(cleantask(), done);
});
但是通过它的原因是什么?
gulp 文档指定的内容类似于以下内容:
var gulp = require('gulp');
// Takes in a callback so the engine knows when it'll be done
// This callback is passed in by Gulp - they are not arguments / parameters
// for your task.
gulp.task('one', function(cb) {
// Do stuff -- async or otherwise
// If err is not null and not undefined, then this task will stop,
// and note that it failed
cb(err);
});
// Identifies a dependent task must be complete before this one begins
gulp.task('two', ['one'], function() {
// Task 'one' is done now, this will now run...
});
gulp.task('default', ['one', 'two']);
done 参数将传递到用于定义任务的回调函数中。
你的任务函数可以"接受回调"函数参数(通常这个函数参数被命名为done
)。执行该done
函数会告诉 Gulp"在任务完成时告诉它的提示"。
如果要对一系列相互依赖的任务进行排序,Gulp 需要此提示,如上例所示。(即任务two
在任务one
调用cb()
之前不会开始)从本质上讲,如果您不希望任务并发运行,它会阻止它们并发运行。
您可以在此处阅读有关此内容的更多信息:https://github.com/gulpjs/gulp/blob/master/docs/API.md#async-task-support