task()
提醒: 这个API不再是推荐的模式了 - export your tasks。因此就不翻译了!
在任务系统中定义任务。然后可以从命令行和 series()
、parallel()
和 lastRun()
api 访问该任务。
Usage
Register a named function as a task:
const { task } = require('gulp');
function build(cb) {
// body omitted
cb();
}
task(build);
Register an anonymous function as a task:
const { task } = require('gulp');
task('build', function(cb) {
// body omitted
cb();
});
Retrieve a task that has been registered previously:
const { task } = require('gulp');
task('build', function(cb) {
// body omitted
cb();
});
const build = task('build');
Signature
task([taskName], taskFunction)
Parameters
If the taskName
is not provided, the task will be referenced by the name
property of a named function or a user-defined displayName
property. The taskName
parameter must be used for anonymous functions missing a displayName
property.
Since any registered task can be run from the command line, avoid using spaces in task names.
parameter | type | note | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
taskName | string | An alias for the task function within the the task system. Not needed when using named functions for taskFunction . | |||||||||||||||
taskFunction (required) | function | A task function or composed task - generated by series() and parallel() . Ideally a named function. ReturnsWhen registering a task, nothing is returned. When retrieving a task, a wrapped task (not the original function) registered as ErrorsWhen registering a task where Task metadata
|