A Docusaurus plugin to integrate TypeDoc with the Docusaurus CLI for generating API documentation.
npx @tessl/cli install tessl/npm-docusaurus-plugin-typedoc@1.4.0A Docusaurus plugin that integrates TypeDoc with the Docusaurus CLI to automatically generate and include TypeScript API documentation in Docusaurus sites. The plugin uses typedoc-plugin-markdown to generate markdown-formatted API documentation that integrates seamlessly with Docusaurus build processes.
npm install docusaurus-plugin-typedoctypedoc-plugin-markdown (>=4.8.0)import docusaurusPluginTypedoc from "docusaurus-plugin-typedoc";
import { PluginOptions } from "docusaurus-plugin-typedoc";For CommonJS:
const docusaurusPluginTypedoc = require("docusaurus-plugin-typedoc");Add the plugin to your docusaurus.config.js:
module.exports = {
plugins: [
[
'docusaurus-plugin-typedoc',
{
entryPoints: ['./src/index.ts'],
tsconfig: './tsconfig.json',
out: './docs/api',
cleanOutputDir: true,
disableSources: true,
hidePageHeader: true,
hideBreadcrumbs: true,
}
]
]
};Or with multiple API documentation instances:
module.exports = {
plugins: [
[
'docusaurus-plugin-typedoc',
{
id: 'api-core',
entryPoints: ['./src/core/index.ts'],
out: './docs/api-core',
tsconfig: './tsconfig.json',
}
],
[
'docusaurus-plugin-typedoc',
{
id: 'api-utils',
entryPoints: ['./src/utils/index.ts'],
out: './docs/api-utils',
tsconfig: './tsconfig.json',
}
]
]
};The plugin architecture consists of:
generate-typedoc command for standalone documentation generationThe main plugin export that integrates TypeDoc generation with Docusaurus.
/**
* Main Docusaurus plugin function for TypeDoc integration
* @param context - Docusaurus load context containing site configuration
* @param opts - Plugin options merged with TypeDoc options
* @returns Promise resolving to Docusaurus plugin object
*/
export default function pluginDocusaurus(
context: LoadContext,
opts: Partial<PluginOptions & TypeDocOptions>
): Promise<{
name: string;
extendCli(cli: Cli): void;
}>;Configuration interface extending TypeDoc plugin options for Docusaurus integration.
/**
* Plugin configuration options interface
* Extends both typedoc-plugin-markdown and typedoc-docusaurus-theme options
*/
export interface PluginOptions
extends TypedocPluginMarkdownOptions, TypedocDocusaurusThemeOptions {}
/** Common options from typedoc-plugin-markdown */
interface TypedocPluginMarkdownOptions {
/** Output file extension (default: '.md') */
fileExtension?: string;
/** Hide page header */
hidePageHeader?: boolean;
/** Hide breadcrumb navigation */
hideBreadcrumbs?: boolean;
/** Hide page title */
hidePageTitle?: boolean;
/** Flatten output files to single directory */
flattenOutputFiles?: boolean;
/** Entry file name */
entryFileName?: string;
/** Modules file name */
modulesFileName?: string;
/** Format for class properties */
classPropertiesFormat?: 'list' | 'table' | 'htmlTable';
/** Format for interface properties */
interfacePropertiesFormat?: 'list' | 'table' | 'htmlTable';
/** Format for enumeration members */
enumMembersFormat?: 'list' | 'table' | 'htmlTable';
/** Format for parameters */
parametersFormat?: 'list' | 'table' | 'htmlTable';
/** Format for type aliases */
typeAliasPropertiesFormat?: 'list' | 'table' | 'htmlTable';
/** Public path for URLs */
publicPath?: string;
/** Exclude scopes in paths */
excludeScopesInPaths?: boolean;
/** Use code blocks for signatures */
useCodeBlocks?: boolean;
/** Expand parameters in signatures */
expandParameters?: boolean;
/** Expand objects in declarations */
expandObjects?: boolean;
/** Clean output directory before generation */
cleanOutputDir?: boolean;
/** Custom anchor prefix */
anchorPrefix?: string;
/** Merge readme with index */
mergeReadme?: boolean;
/** Members with own files */
membersWithOwnFile?: ('Enum' | 'Variable' | 'Function' | 'Class' | 'Interface' | 'TypeAlias')[];
}
/** Options from typedoc-docusaurus-theme */
interface TypedocDocusaurusThemeOptions {
/** The value of the Docusaurus docs.path config option */
docsPath?: string;
/** The value of the Docusaurus numberPrefixParser option */
numberPrefixParser?: boolean;
/** Configures the autogenerated sidebar */
sidebar?: Sidebar;
}Docusaurus load context interface providing site configuration and directory information.
interface LoadContext {
/** Root directory of the Docusaurus site */
siteDir: string;
/** Site configuration object */
siteConfig: {
/** Array of configured plugins */
plugins?: any[];
/** Array of configured presets */
presets?: any[];
};
}Command-line interface builder for extending Docusaurus CLI.
interface Cli {
/** Add a new command to the CLI */
command(name: string): Cli;
/** Set description for the current command */
description(desc: string): Cli;
/** Add an option flag to the current command */
option(flag: string, desc?: string): Cli;
/** Set the action function for the current command */
action(fn: (...args: any[]) => void): void;
}Common TypeDoc configuration options used by the plugin.
interface TypeDocOptions {
/** TypeScript configuration file path */
tsconfig?: string;
/** Entry points for TypeDoc analysis */
entryPoints?: string[];
/** Output directory for generated documentation */
out?: string;
/** TypeDoc plugins to load */
plugin?: string[];
/** Whether to watch for file changes */
watch?: boolean;
/** Clean output directory before generation */
cleanOutputDir?: boolean;
/** Disable source code links */
disableSources?: boolean;
/** Hide page headers in generated docs */
hidePageHeader?: boolean;
/** Hide breadcrumb navigation */
hideBreadcrumbs?: boolean;
/** TypeDoc logging level */
logLevel?: 'Verbose' | 'Info' | 'Warn' | 'Error';
/** Readme handling mode */
readme?: 'none' | string;
}Sidebar configuration interface for Docusaurus theme options.
interface Sidebar {
/** Enable automatic sidebar configuration */
autoConfiguration: boolean;
/** Use pretty formatting in sidebar */
pretty: boolean;
/** Include TypeScript-specific configuration */
typescript: boolean;
/** CSS class name for deprecated items */
deprecatedItemClassName: string;
}The plugin adds a generate-typedoc command to the Docusaurus CLI:
npx docusaurus generate-typedocThis command generates TypeDoc documentation independently of the Docusaurus build process, using the same configuration from your docusaurus.config.js plugins array.
The plugin applies these default configurations:
./docs/apitypedoc-plugin-markdown and typedoc-docusaurus-theme are automatically included