@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
appDir configures the base directory for parsing. The default is process.cwd().
entries
entries configures the files to parse.
- The key is an identifier used as the
moduleNameattribute of theAPIcomponent. - The value is the relative path to the file being parsed.
apiParseTool
apiParseTool selects the parser. The default is react-docgen-typescript:
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
parseToolOptions passes options to the selected parser. Its type is:
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.