@rspress/plugin-api-docgen
This plugin generates API reference content automatically, powered by react-docgen-typescript and documentation.
Install
Usage
First, add the following configuration:
Then use the API component to inject API documentation into an MDX file:
Internationalization
This plugin uses the plugin API i18nSource to add the following translations:
Translation source
You can override these texts with the user configuration i18nSource.
Config
The plugin accepts an object with the following type:
appDir
- Type:
string - Default:
process.cwd()
Sets the base directory for parsing.
entries
- Type:
Entries | ToolEntries - Default:
{}
Lists the files to parse. Pass an Entries map directly, or use ToolEntries to provide a separate map for each parser.
- The key is an identifier used as the
moduleNameattribute of theAPIcomponent. - The value is the relative path to the file being parsed.
apiParseTool
- Type:
'react-docgen-typescript' | 'documentation' - Default:
'react-docgen-typescript'
Selects the parser:
react-docgen-typescriptis used for component library scenarios. It parses props to generate tables.
In this standard form, ButtonProps is extracted into a table and Button is used as the table title.
If you use a default export, the file name is used as the table title.
Note that exports declared elsewhere are not available.
The generated content is as follows:
If props use React types, add those types in tsconfig.json; otherwise, types under the React namespace cannot be resolved.
The best approach is to import the type directly:
documentationis used in utility library scenarios to parse JSDoc annotations. Here is agreetfunction with JSDoc annotations.
The generated content is as follows:
parseToolOptions
- Type:
- Default:
{}
Passes options to the selected parser.
See ParserOptions and DocumentationArgs for available options.
When the parser is react-docgen-typescript, withDefaultConfig creates the parser instance by default. If tsconfigPath or compilerOptions is configured, they can be set separately for each entry; withCompilerOptions and withCustomConfig are used to create the parser instance respectively. See Custom Parsers for details.