gulp.js 中文文档
  • 入门指南
  • API文档
  • 旧版文档
  • 插件
  • Twitter
  • 博客
  • 英文官网

›API

入门指南

  • 快速入门
  • JavaScript 和 Gulpfile
  • 创建任务(task)
  • 异步执行
  • 处理文件
  • Glob 详解
  • 使用插件
  • 文件监控

API

  • Concepts
  • src()
  • dest()
  • symlink()
  • lastRun()
  • series()
  • parallel()
  • watch()
  • task()
  • registry()
  • tree()
  • Vinyl
  • Vinyl.isVinyl()
  • Vinyl.isCustomProp()

tree()

获取当前任务依赖关系树——在极少数情况下需要它。

通常,gulp 使用者不会使用 tree(),但它是公开的,因此 CLI 可以显示在 gulpfile 中定义的任务的依赖关系图。

用法

Example gulpfile:


const { series, parallel } = require('gulp');

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

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

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

const four = series(one, two);

const five = series(four,
  parallel(three, function(cb) {
    // Body omitted
    cb();
  })
);

module.exports = { one, two, three, four, five };

tree() 的输出:

{
  label: 'Tasks',
  nodes: [ 'one', 'two', 'three', 'four', 'five' ]
}

tree({ deep: true }) 的输出:

{
  label: "Tasks",
  nodes: [
    {
      label: "one",
      type: "task",
      nodes: []
    },
    {
      label: "two",
      type: "task",
      nodes: []
    },
    {
      label: "three",
      type: "task",
      nodes: []
    },
    {
      label: "four",
      type: "task",
      nodes: [
        {
          label: "<series>",
          type: "function",
          branch: true,
          nodes: [
            {
              label: "one",
              type: "function",
              nodes: []
            },
            {
              label: "two",
              type: "function",
              nodes: []
            }
          ]
        }
      ]
    },
    {
      label: "five",
      type: "task",
      nodes: [
        {
          label: "<series>",
          type: "function",
          branch: true,
          nodes: [
            {
              label: "<series>",
              type: "function",
              branch: true,
              nodes: [
                {
                  label: "one",
                  type: "function",
                  nodes: []
                },
                {
                  label: "two",
                  type: "function",
                  nodes: []
                }
              ]
            },
            {
              label: "<parallel>",
              type: "function",
              branch: true,
              nodes: [
                {
                  label: "three",
                  type: "function",
                  nodes: []
                },
                {
                  label: "<anonymous>",
                  type: "function",
                  nodes: []
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

函数原型

tree([options])

参数

参数类型描述
optionsobject详情请见下文 选项 。

返回值

返回一个详细描述已注册的任务树的对象——包含具有 'label' 和 'nodes' 属性的嵌套对象(与 archy 兼容)。

每个对象可能有一个 type 属性,用于确定节点是 task 还是 function。

每个对象可能有一个 branch 属性,当 true 时,该属性指示节点是使用 series() 还是 parallel() 创建的。

选项

nametypedefaultnote
deepbooleanfalse如果为 true,则返回整个树。如果为 false,则只返回顶级任务。
← registry()Vinyl →
  • 用法
  • 函数原型
    • 参数
    • 返回值
    • 选项
gulp.js 中文文档
中文文档
入门指南API 参考手册
社区
Stack OverflowTwitter
更多
GitHubStar
Copyright © 2020 GulpJS