Gulp task()

🌙
手机阅读
本文目录结构

task()

提醒: 这个 API 不再推荐使用!

在任务系统中定义任务。然后可以从命令行和 series()parallel()lastRun() api 访问该任务。

Usage

将命名函数注册为任务

const { task } = require('gulp');

function build(cb) {
  // body omitted
  cb();
}

task(build);

将匿名函数注册为任务:

const { task } = require('gulp');

task('build', function(cb) {
  // body omitted
  cb();
});

检索先前已注册的任务:

const { task } = require('gulp');

task('build', function(cb) {
  // body omitted
  cb();
});

const build = task('build');

Signature

task([taskName], taskFunction)

Parameters

如果未提供taskName,则该任务将由命名函数的name属性或用户定义的displayName属性引用。 taskName参数必须用于缺少displayName属性的匿名函数。

由于可以从命令行运行任何已注册的任务,因此请避免在任务名称中使用空格。

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. Task metadata can be attached to provide extra information to the command line.

Returns

注册任务时,不返回任何内容。

检索任务时,将返回注册为taskName的包装任务(不是原始函数)。 包装的任务有一个unwrap()方法,该方法将返回原始函数。

Errors

当注册一个缺少taskName并且taskFunction是匿名的任务时,将引发错误消息“必须指定任务名称”。

Task metadata

property type note
name string A special property of named functions. Used to register the task.
Note: name is not writable; it cannot be set or changed.
displayName string When attached to a taskFunction creates an alias for the task. If using characters that aren’t allowed in function names, use this property.
description string When attached to a taskFunction provides a description to be printed by the command line when listing tasks.
flags object When attached to a taskFunction provides flags to be printed by the command line when listing tasks. The keys of the object represent the flags and the values are their descriptions.
const { task } = require('gulp');

const clean = function(cb) {
  // body omitted
  cb();
};
clean.displayName = 'clean:all';

task(clean);

function build(cb) {
  // body omitted
  cb();
}
build.description = 'Build the project';
build.flags = { '-e': 'An example flag' };

task(build);

AXIHE / 精选资源

浏览全部教程

面试题

学习网站

前端培训
自己甄别

前端书籍

关于朱安邦

我叫 朱安邦,阿西河的站长,在杭州。

以前是一名平面设计师,后来开始接接触前端开发,主要研究前端技术中的JS方向。

业余时间我喜欢分享和交流自己的技术,欢迎大家关注我的 Bilibili

关注我: Github / 知乎

于2021年离开前端领域,目前重心放在研究区块链上面了

我叫朱安邦,阿西河的站长

目前在杭州从事区块链周边的开发工作,机械专业,以前从事平面设计工作。

2014年底脱产在老家自学6个月的前端技术,自学期间几乎从未出过家门,最终找到了满意的前端工作。更多>

于2021年离开前端领域,目前从事区块链方面工作了