Integration of TypeDoc's Rspress Plugin for Automatically Generating API Documentation for TS Modules.
npm add @rspress/plugin-typedoc -Dimport { defineConfig } from '@rspress/core';
import { pluginTypeDoc } from '@rspress/plugin-typedoc';
import path from 'path';
export default defineConfig({
plugins: [
pluginTypeDoc({
entryPoints: [
path.join(__dirname, 'src', 'foo.ts'),
path.join(__dirname, 'src', 'bar.ts'),
],
}),
],
});/**
* This is an add function.
*/
export function add(
/**
* This is param1.
*/
param1: string,
/**
* This is param2.
*/
param2: number,
) {
return 1;
}/**
* This is a multi function.
*/
export function multi(
/**
* This is param1.
*/
param1?: string,
/**
* This is param2.
*/
param2?: number,
) {
return 1;
}When you start/build the project, the plugin will automatically generate an api directory in your document root directory. The directory structure is as follows:
api
βββ README.md
βββ documentation.json
βββ functions
β βββ bar.multi.md
β βββ foo.add.md
βββ interfaces
β βββ foo.RunTestsOptions.md
β βββ foo.TestMessage.md
βββ modules
βββ bar.md
βββ foo.mdThis means that the plugin will internally call TypeDoc to automatically generate API documentation for your modules, including module lists, Interface details, function details (parameters, return values, description), etc. It will also generate a documentation.json file for subsequent sidebar rendering.
Note that the documentation is regenerated every time you start the project to reflect the latest module content. Therefore, we recommend adding the api directory to .gitignore. If you customize the output directory with the outDir parameter below, you should also add it to .gitignore.
Also, we do not recommend modifying or adding documents in the api directory because these documents will be overwritten each time the project is started due to changes in module content.
string[][]Specifies the absolute path of the TS modules for which documentation should be generated.
stringapiCustomize the output directory for the documentation. You need to provide a relative path, such as api/custom.