Use Rspress
Rspress is a Rspack-based static site generator, ideal for building demos and API docs for component libraries. With plugin-preview and plugin-api-docgen, you can reuse Rslib sources and typings to preview components and view APIs in one site.
New project
When using create-rslib, choose the React + TypeScript template and enable the extra tool “Rspress - documentation” to auto-generate docs folder, scripts, and Rspress config—no manual setup needed.
Run npm create rslib@latest and select Rspress to get the following structure:
The template includes rsbuild-plugin-workspace-dev, which will run Rslib watch while the Rspress dev server is running.
Run npm run doc to start the Rspress dev server and preview your Rslib components:
Existing project
If you are using Rslib to build a component library, follow these steps to add Rspress documentation support.
Install deps
Add scripts in package.json
Create rspress.config.ts
Add preview-related plugins like plugin-preview and plugin-api-docgen.
Import built output by package name
Set paths in tsconfig.json to point to your package, or declare your package as a dependency via "workspace:*" in package.json, so plugin-preview resolves demos from the built artifact.
In plugin-preview, we recommend importing component outputs by package name rather than relative paths. This keeps the preview environment consistent with how users consume the library.
If your project uses the exports field, we recommend "workspace:*" instead:
This approach avoids changes to tsconfig.json and supports multi-entry exports.
Example
Add docs under docs/ (see the template’s docs/Button.mdx):
