npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@spalladino/docusaurus-plugin-typedoc

v0.20.3

Published

A Docusaurus v2 plugin to build API documentation with TypeDoc.

Downloads

2

Readme

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.

| Name | Default | Description | | :---------------------- | :------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | out | "api" | Output dir relative to docs dir (use . for no subdir). | | includeExtension | true | Determines whether to preserve the .md extension in relative links. true is recommended as per Docusaurus documentation | | frontmatter | null | Additional frontmatter options object. See Frontmatter. | | sidebar.categoryLabel | API | The sidebar parent category label. | | sidebar.collapsed | true | Whether the parent category is initially collapsed | | sidebar.fullNames | false | Display full names with module path. | | sidebar.position | auto | The 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