TypeDoc 配置 #

配置文件位置 #

TypeDoc 支持多种配置文件位置,按优先级从高到低:

text
┌─────────────────────────────────────────────────────────────┐
│                    配置文件优先级                            │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  1. typedoc.json(推荐)                                    │
│     项目根目录                                              │
│                                                             │
│  2. typedoc.js                                              │
│     JavaScript 格式配置文件                                 │
│                                                             │
│  3. package.json                                            │
│     typedocOptions 字段                                     │
│                                                             │
│  4. tsconfig.json                                           │
│     typedocOptions 字段                                     │
│                                                             │
└─────────────────────────────────────────────────────────────┘

输入配置 #

entryPoints #

指定文档的入口文件或目录。

json
{
  "entryPoints": ["src/index.ts"]
}

多个入口点:

json
{
  "entryPoints": [
    "src/core/index.ts",
    "src/utils/index.ts",
    "src/plugins/index.ts"
  ]
}

带显示名称的入口点:

json
{
  "entryPoints": [
    {
      "entryPoint": "src/core/index.ts",
      "displayName": "Core Module"
    },
    {
      "entryPoint": "src/utils/index.ts",
      "displayName": "Utility Functions"
    }
  ]
}

entryPointStrategy #

入口点解析策略。

json
{
  "entryPointStrategy": "resolve"
}

可选值:

说明
resolve 默认值,将入口点解析为模块
packages Monorepo 模式,每个包独立处理
merge 合并多个入口点为单一模块

tsconfig #

指定 TypeScript 配置文件路径。

json
{
  "tsconfig": "./tsconfig.build.json"
}

compilerOptions #

覆盖 TypeScript 编译选项。

json
{
  "compilerOptions": {
    "skipLibCheck": true,
    "noImplicitAny": false
  }
}

exclude #

排除不需要生成文档的文件。

json
{
  "exclude": [
    "node_modules",
    "dist",
    "**/*.test.ts",
    "**/*.spec.ts",
    "src/internal/**"
  ]
}

externalPattern #

指定外部模块的匹配模式。

json
{
  "externalPattern": [
    "**/node_modules/**",
    "**/vendor/**"
  ]
}

输出配置 #

out #

指定 HTML 文档输出目录。

json
{
  "out": "docs"
}

json #

同时输出 JSON 格式的文档数据。

json
{
  "json": "docs/api.json"
}

pretty #

格式化 JSON 输出。

json
{
  "pretty": true
}

cleanOutputDir #

生成前清空输出目录。

json
{
  "cleanOutputDir": true
}

emit #

控制输出行为。

json
{
  "emit": "docs"
}

可选值:

说明
docs 只生成文档
both 生成文档和编译输出
none 不生成任何输出

显示配置 #

name #

文档站点名称。

json
{
  "name": "My Project API Documentation"
}

includeVersion #

在文档中包含项目版本号。

json
{
  "includeVersion": true
}

readme #

指定 README 文件路径。

json
{
  "readme": "./README.md"
}

不显示 README:

json
{
  "readme": "none"
}

favicon #

自定义网站图标。

json
{
  "favicon": "./assets/favicon.ico"
}

hideGenerator #

隐藏生成器标识。

json
{
  "hideGenerator": true
}

customFooter #

自定义页脚内容。

json
{
  "customFooter": "© 2024 My Company"
}

customFooterHtml #

自定义页脚 HTML。

json
{
  "customFooterHtml": "<p>Built with <a href='https://typedoc.org'>TypeDoc</a></p>"
}

过滤配置 #

excludePrivate #

排除私有成员。

json
{
  "excludePrivate": true
}

excludeProtected #

排除受保护成员。

json
{
  "excludeProtected": false
}

excludeInternal #

排除标记为 @internal 的成员。

json
{
  "excludeInternal": true
}

excludeExternals #

排除外部依赖。

json
{
  "excludeExternals": true
}

excludeNotDocumented #

排除没有文档注释的成员。

json
{
  "excludeNotDocumented": true
}

excludeReferences #

排除重导出的引用。

json
{
  "excludeReferences": true
}

visibilityFilters #

自定义可见性过滤器。

json
{
  "visibilityFilters": {
    "protected": true,
    "private": false,
    "inherited": true,
    "external": false,
    "@internal": false,
    "@alpha": true
  }
}

排序配置 #

sort #

设置成员排序方式。

json
{
  "sort": ["source-order"]
}

可选值:

说明
source-order 按源代码顺序
alphabetical 按字母顺序
enum-value-ascending 枚举值升序
enum-value-descending 枚举值降序
static-first 静态成员优先
instance-first 实例成员优先
visibility 按可见性排序

多个排序规则:

json
{
  "sort": ["static-first", "visibility", "alphabetical"]
}

kindSortOrder #

自定义类型排序顺序。

json
{
  "kindSortOrder": [
    "Reference",
    "Project",
    "Module",
    "Namespace",
    "Enum",
    "EnumMember",
    "Class",
    "Interface",
    "TypeAlias",
    "Function",
    "Variable"
  ]
}

搜索配置 #

searchInComments #

在注释中搜索。

json
{
  "searchInComments": true
}

searchInDocuments #

在文档中搜索。

json
{
  "searchInDocuments": true
}

主题配置 #

theme #

指定主题。

json
{
  "theme": "default"
}

lightHighlightTheme #

代码高亮主题(浅色)。

json
{
  "lightHighlightTheme": "light-plus"
}

darkHighlightTheme #

代码高亮主题(深色)。

json
{
  "darkHighlightTheme": "dark-plus"
}

可用主题:

主题 说明
light-plus VS Code 浅色主题
dark-plus VS Code 深色主题
github-light GitHub 浅色主题
github-dark GitHub 深色主题

分类配置 #

categorizeByGroup #

按组分类成员。

json
{
  "categorizeByGroup": true
}

defaultCategory #

默认分类名称。

json
{
  "defaultCategory": "Other"
}

categoryOrder #

分类排序顺序。

json
{
  "categoryOrder": [
    "Core",
    "Utilities",
    "Helpers",
    "*"
  ]
}

groupOrder #

分组排序顺序。

json
{
  "groupOrder": [
    "Classes",
    "Interfaces",
    "Functions",
    "Variables",
    "*"
  ]
}

导航配置 #

导航配置选项。

json
{
  "navigation": {
    "includeCategories": true,
    "includeGroups": true,
    "compactFolders": true
  }
}

自定义导航链接。

json
{
  "navigationLinks": {
    "GitHub": "https://github.com/user/repo",
    "NPM": "https://www.npmjs.com/package/my-package"
  }
}

侧边栏链接。

json
{
  "sidebarLinks": {
    "API Reference": "/api",
    "Examples": "/examples"
  }
}

评论配置 #

commentStyle #

注释风格。

json
{
  "commentStyle": "jsdoc"
}

可选值:

说明
jsdoc JSDoc 风格(默认)
block 块注释风格

useTsLinkResolution #

使用 TypeScript 链接解析。

json
{
  "useTsLinkResolution": true
}

插件配置 #

plugin #

指定要加载的插件。

json
{
  "plugin": [
    "typedoc-plugin-markdown",
    "typedoc-theme-hierarchy"
  ]
}

禁用所有插件:

json
{
  "plugin": []
}

监听模式 #

watch #

启用监听模式。

bash
npx typedoc --watch

preserveWatchOutput #

保留监听输出。

bash
npx typedoc --watch --preserveWatchOutput

服务器模式 #

serve #

启动本地服务器。

bash
npx typedoc --serve

host #

服务器主机地址。

json
{
  "host": "localhost"
}

port #

服务器端口。

json
{
  "port": 3000
}

完整配置示例 #

开源库配置 #

json
{
  "$schema": "https://typedoc.org/schema.json",
  "entryPoints": ["src/index.ts"],
  "out": "docs",
  "name": "My Library",
  "includeVersion": true,
  "readme": "./README.md",
  "excludePrivate": true,
  "excludeInternal": true,
  "excludeExternals": true,
  "hideGenerator": false,
  "searchInComments": true,
  "sort": ["source-order"],
  "navigationLinks": {
    "GitHub": "https://github.com/user/my-library",
    "NPM": "https://www.npmjs.com/package/my-library"
  },
  "visibilityFilters": {
    "protected": true,
    "private": false,
    "inherited": true,
    "external": false
  }
}

企业项目配置 #

json
{
  "$schema": "https://typedoc.org/schema.json",
  "entryPoints": [
    "src/core/index.ts",
    "src/api/index.ts",
    "src/utils/index.ts"
  ],
  "out": "docs/api",
  "name": "Enterprise API Documentation",
  "includeVersion": true,
  "favicon": "./docs/assets/favicon.ico",
  "customFooter": "© 2024 Enterprise Inc.",
  "hideGenerator": true,
  "exclude": [
    "**/*.test.ts",
    "**/*.spec.ts",
    "src/internal/**"
  ],
  "excludePrivate": true,
  "excludeProtected": false,
  "excludeInternal": true,
  "sort": ["static-first", "visibility", "alphabetical"],
  "categoryOrder": ["Public API", "Internal", "*"],
  "navigationLinks": {
    "Dashboard": "/dashboard",
    "API Status": "/status"
  },
  "theme": "default",
  "lightHighlightTheme": "github-light",
  "darkHighlightTheme": "github-dark"
}

Monorepo 配置 #

json
{
  "$schema": "https://typedoc.org/schema.json",
  "entryPointStrategy": "packages",
  "entryPoints": [
    "packages/core",
    "packages/utils",
    "packages/cli",
    "packages/plugins"
  ],
  "out": "docs",
  "name": "Monorepo Documentation",
  "includeVersion": true,
  "excludePrivate": true,
  "excludeInternal": true,
  "sort": ["source-order"],
  "visibilityFilters": {
    "protected": true,
    "private": false,
    "inherited": true,
    "external": false
  },
  "searchInComments": true,
  "cleanOutputDir": true
}

配置继承 #

extends #

继承基础配置。

json
// typedoc.base.json
{
  "excludePrivate": true,
  "excludeInternal": true,
  "sort": ["source-order"]
}

// typedoc.json
{
  "extends": ["./typedoc.base.json"],
  "entryPoints": ["src/index.ts"],
  "out": "docs",
  "name": "My Project"
}

命令行覆盖 #

命令行参数可以覆盖配置文件:

bash
# 覆盖输出目录
npx typedoc --out custom-docs

# 覆盖多个选项
npx typedoc --out docs --name "Custom Name" --excludePrivate false

# 使用配置文件并覆盖
npx typedoc --options typedoc.prod.json --out production-docs

下一步 #

现在你已经掌握了 TypeDoc 的配置选项,接下来学习 注解标签,了解如何使用各种 JSDoc 标签来丰富文档内容!

最后更新:2026-03-29