registry()#

允许将自定义注册表插入到任务系统中,该系统可以提供共享任务或增强功能。

¥Allows custom registries to be plugged into the task system, which can provide shared tasks or augmented functionality.

注意:只有使用 task() 注册的任务才会提供给自定义注册表。不提供直接传递给 series()parallel() 的任务函数 - 如果你需要自定义注册表行为,请使用字符串引用编写任务。

¥Note: Only tasks registered with task() will be provided to the custom registry. The task functions passed directly to series() or parallel() will not be provided - if you need to customize the registry behavior, compose tasks with string references.

分配新注册表时,当前注册表中的每项任务都将被转移,并且当前注册表将被新注册表替换。这允许按顺序添加多个自定义注册表。

¥When assigning a new registry, each task from the current registry will be transferred and the current registry will be replaced with the new one. This allows for adding multiple custom registries in sequential order.

详情请参见 创建自定义注册表

¥See Creating Custom Registries for details.

用法#

¥Usage

const { registry, task, series } = require('gulp');
const FwdRef = require('undertaker-forward-reference');
registry(FwdRef());
task('default', series('forward-ref'));
task('forward-ref', function(cb) {
// body omitted
cb();
});

签名#

¥Signature

registry([registryInstance])

参数#

¥Parameters

参数typenote
registryInstanceobject一个实例 - 不是类 - 自定义注册表的。

返回#

¥Returns

如果通过了 registryInstance,则不会返回任何内容。如果未传递参数,则返回当前注册表实例。

¥If a registryInstance is passed, nothing will be returned. If no arguments are passed, returns the current registry instance.

错误#

¥Errors

参数错误#

¥Incorrect parameter

当构造函数(而不是实例)作为 registryInstance 传递时,会抛出错误并显示以下消息:

¥When a constructor (instead of an instance) is passed as registryInstance, throws an error with the message:

自定义注册表必须实例化,但看起来你传递了一个构造函数。

¥Custom registries must be instantiated, but it looks like you passed a constructor.

缺少 get 方法#

¥Missing get method

当没有 get 方法的注册表作为 registryInstance 传递时,会抛出错误并显示以下消息:

¥When a registry without a get method is passed as registryInstance, throws an error with the message:

自定义注册表必须具有 get 功能。

¥Custom registry must have get function.

缺少 set 方法#

¥Missing set method

当没有 set 方法的注册表作为 registryInstance 传递时,会抛出错误并显示以下消息:

¥When a registry without a set method is passed as registryInstance, throws an error with the message:

自定义注册表必须具有 set 功能。

¥Custom registry must have set function.

缺少 init 方法#

¥Missing init method

当没有 init 方法的注册表作为 registryInstance 传递时,会抛出错误并显示以下消息:

¥When a registry without an init method is passed as registryInstance, throws an error with the message:

自定义注册表必须具有 init 功能”

¥Custom registry must have init function"

缺少 tasks 方法#

¥Missing tasks method

当没有 tasks 方法的注册表作为 registryInstance 传递时,会抛出错误并显示以下消息:

¥When a registry without a tasks method is passed as registryInstance, throws an error with the message:

自定义注册表必须具有 tasks 功能。

¥Custom registry must have tasks function.