@convex-dev/docusaurus-plugin-typedoc

中文文档
0.19.2发布于 2023/05/03MITCommonJS零依赖近 30 天下载 1万

A Docusaurus v2 plugin to build API documentation with TypeDoc.

原始使用文档
文档目录16 节
  1. What does it do?
  2. Installation
  3. Usage
  4. Config
  5. Directory structure
  6. Options
  7. TypeDoc options
  8. Plugin options
  9. An example configuration
  10. Recipes
  11. Sidebar and Navbar
  12. Frontmatter
  13. Multi instance
  14. Watch mode
  15. Monorepo setup
  16. License

docusaurus-plugin-typedoc

A Docusaurus v2 plugin to build documentation with TypeDoc.

npm CI

What does it do?

Generates static TypeDoc pages in Markdown with frontmatter as part of the Docusaurus build.

Installation

Install Docusaurus in the root of your project and install the plugin dependencies in the same location as the Docusaurus website directory.

npm install typedoc typedoc-plugin-markdown docusaurus-plugin-typedoc --save-dev

Usage

Config

Add the plugin to docusaurus.config.js and specify the required options (see options).

module.exports = {
  plugins: [
    [
      'docusaurus-plugin-typedoc',

      // Plugin / TypeDoc options
      {
        entryPoints: ['../src/index.ts'],
        tsconfig: '../tsconfig.json',
      },
    ],
  ],
};

TypeDoc will be bootstraped with the Docusaurus start and build cli commands:

"start": "docusaurus start",
"build": "docusaurus build",

Once built the docs will be available at /docs/api (or equivalent out directory).

Directory structure

├── docusauruss-website
    ├── build/ (static site dir)
    ├── docs/
    │   ├── api/ (compiled typedoc markdown)
    ├── docusaurus.config.js
    ├── package.json
    ├── sidebars.js
├──package.json
├──src (typescript source files)
├──tsconfig.json

Options

TypeDoc options

To configure TypeDoc, pass any relevant TypeDoc options to the config.

At a minimum the entryPoints and tsconfig options will need to be set.

entryPoints: ['../src/index.ts'],
tsconfig: '../tsconfig.json'

Additional TypeDoc plugins will need to be explicitly set:

plugin: ['typedoc-plugin-xyz'];

Other config options

TypeDoc options can also be declared:

  • Using a typedoc.json file.
  • Under the typedocOptions key in tsconfig.json.

Note: Options declared in this manner will take priority and overwrite options declared in docusaurus.config.js.

Plugin options

Options specific to the plugin should also be declared in the same object.

NameDefaultDescription
out"api"Output dir relative to docs dir (use . for no subdir).
includeExtensiontrueDetermines whether to preserve the .md extension in relative links. true is recommended as per Docusaurus documentation
frontmatternullAdditional frontmatter options object. See Frontmatter.
sidebar.categoryLabelAPIThe sidebar parent category label.
sidebar.collapsedtrueWhether the parent category is initially collapsed
sidebar.fullNamesfalseDisplay full names with module path.
sidebar.positionautoThe position of the sidebar in the tree.

An example configuration

module.exports = {
  plugins: [
    [
      'docusaurus-plugin-typedoc',
      {
        // TypeDoc options
        entryPoints: ['../src/index.ts'],
        tsconfig: '../tsconfig.json',
        plugin: ['typedoc-plugin-xyz'],

        // Plugin options
        out: 'api-xyz',
        sidebar: {
          categoryLabel: 'API XYZ',
          collapsed: false,
          position: 0,
          fullNames: true,
        },
      },
    ],
  ],
};

Recipes

Sidebar and Navbar

Sidebar

sidebars.js can be configured in following ways:

  1. Generate the entire sidebar from file structure of your docs folder (default behaviour):
module.exports = {
  sidebar: [
    {
      type: 'autogenerated',
      dirName: '.', // '.' means the docs folder
    },
  ],
};
  1. Alternatively, if you wish to manually control other parts of your sidebar you can use a slice for the TypeDoc sidebar.

note: sidebar.categoryLabel, sidebar.collapsed, and sidebar.position options are ignored with this implementation)

module.exports = {
  sidebar: {
    'Category 1': ['doc1', 'doc2', 'doc3'],
    API: [
      {
        type: 'autogenerated',
        dirName: 'api', // 'api' is the 'out' directory
      },
    ],
  },
};

Please see https://docusaurus.io/docs/sidebar for sidebar documentation.

Navbar

A navbar item can be configured in themeConfig options in docusaurus.config.js:

 themeConfig: {
    navbar: {
      items: [
        {
        to: 'docs/api/',  // 'api' is the 'out' directory
        activeBasePath: 'docs',
        label: 'API',
        position: 'left',
      },
    ],
  },
},

Please see https://docusaurus.io/docs/api/themes/configuration#navbar-items for navbar documentation.

Frontmatter

By default the plugin will configure minimal required Frontmatter configuration. Additionally required global Frontmatter options can be passed in using the frontmatter options object

docusaurus.config.js:

plugins: [
    [
      'docusaurus-plugin-typedoc',
      {
      // .... other plugin option
      frontmatter: {
        pagination_prev: null,
        pagination_next: null
      }
    ]
]

Multi instance

It is possible to build multi TypeDoc instances by passing in multiple configs with unique ids:

docusaurus.config.js

module.exports = {
  plugins: [
    [
      'docusaurus-plugin-typedoc',
      {
        id: 'api-1',
        entryPoints: ['../api-1/src/index.ts'],
        tsconfig: '../api-1/tsconfig.json',
        out: 'api-1',
      },
    ],
    [
      'docusaurus-plugin-typedoc',
      {
        id: 'api-2',
        entryPoints: ['../api-2/src/index.ts'],
        tsconfig: '../api-2/tsconfig.json',
        out: 'api-2',
      },
    ],
  ],
};

Watch mode

Watching files is supported by passing in the watch: true option see https://typedoc.org/guides/options/#watch.

Targetting the option in development mode only can be achieved using Node.js Environment Variables:

package.json

"start": "TYPEDOC_WATCH=true docusaurus start",
"build": "TYPEDOC_WATCH=false docusaurus build",

docusaurus.config.js

module.exports = {
  plugins: [
    [
      'docusaurus-plugin-typedoc',
      {
        entryPoints: ['../src/index.ts'],
        tsconfig: '../tsconfig.json',
        watch: process.env.TYPEDOC_WATCH,
      },
    ],
  ],
};

Monorepo setup

docusaurus.config.js

module.exports = {
  plugins: [
    [
      'docusaurus-plugin-typedoc',
      {
        entryPoints: ['../packages/package-a', '../packages/package-b'],
        entryPointStrategy: 'packages',
        sidebar: {
          fullNames: true,
        },
      },
    ],
  ],
};

License

MIT

版本与发布记录

@convex-dev/docusaurus-plugin-typedoc 共发布 5 个版本,首次发布于 2023/03/03;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.19.2latest2023/05/033 年前
0.18.32023/03/033 年前
0.18.22023/03/033 年前
0.18.12023/03/033 年前
0.18.02023/03/033 年前

关于 @convex-dev/docusaurus-plugin-typedoc 的常见问题

@convex-dev/docusaurus-plugin-typedoc 是什么?

A Docusaurus v2 plugin to build API documentation with TypeDoc.

如何安装 @convex-dev/docusaurus-plugin-typedoc?

在项目目录运行 npm install @convex-dev/docusaurus-plugin-typedoc,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:typedoc(>=0.24.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@convex-dev/docusaurus-plugin-typedoc 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/convex-dev__docusaurus-plugin-typedoc 是否存在。

@convex-dev/docusaurus-plugin-typedoc 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@convex-dev/docusaurus-plugin-typedoc 可以商用吗?

@convex-dev/docusaurus-plugin-typedoc 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@convex-dev/docusaurus-plugin-typedoc 的下载量有多少?

根据 npm 官方下载统计,@convex-dev/docusaurus-plugin-typedoc 在 2026/10/11 – 2026/11/09 这 30 天内被下载 10,415 次,日均约 347 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@convex-dev/docusaurus-plugin-typedoc 还在维护吗?

最新版本 0.19.2 发布于 2023/05/03(3 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/03/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。