Render interactive Scalar API Reference pages from an OpenAPI specification, inside your Rspress documentation site.
Mount one or more Scalar API Reference instances at custom routes of your Rspress site. The plugin inherits the host site's theme via shared CSS variables and follows the site's light/dark mode automatically.
- Drop-in route — declare a route, point it at an OpenAPI document, done.
- Multiple instances — serve several APIs (public, admin, internal) from one site with a single Scalar runtime.
- Theme-aware — light/dark mode follows Rspress; visual tokens inherit from the host theme.
- CDN-loaded — Scalar bundle is loaded from jsDelivr; pin a version when you need reproducibility.
- Type-safe config — configuration types are re-exported from
@scalar/types.
npm install @seshuk/rspress-plugin-scalar
# or
pnpm add @seshuk/rspress-plugin-scalar
# or
bun add @seshuk/rspress-plugin-scalarNote
Requires @rspress/core v2 and React 18 or 19 as peer dependencies.
Register the plugin in your rspress.config.ts:
import { defineConfig } from '@rspress/core'
import { pluginScalar } from '@seshuk/rspress-plugin-scalar'
export default defineConfig({
plugins: [
pluginScalar({
instances: [
{
route: '/scalar',
configuration: {
url: '/openapi.json',
},
},
],
}),
],
})The OpenAPI document referenced by url should be reachable from the site (for example, place openapi.json in your public/ folder).
Serve several API references from one site — a single Scalar bundle is loaded and shared:
pluginScalar({
instances: [
{ route: '/scalar', configuration: { url: '/openapi.json' } },
{ route: '/scalar-admin', configuration: { url: '/admin.json' } },
],
})By default the latest Scalar bundle is loaded from jsDelivr. Pin a version for reproducible builds:
pluginScalar({
cdn: 'https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.55.3',
instances: [{ route: '/scalar', configuration: { url: '/openapi.json' } }],
})| Option | Type | Default | Description |
|---|---|---|---|
instances |
ScalarInstanceOptions[] |
— | Required. One or more API Reference instances. Routes must be unique. |
cdn |
string |
https://cdn.jsdelivr.net/npm/@scalar/api-reference |
URL of the Scalar bundle. Pin a version for reproducibility. |
| Option | Type | Default | Description |
|---|---|---|---|
route |
string |
'/scalar' |
Route at which the API Reference is mounted. |
configuration |
AnyApiReferenceConfiguration |
— | Required. Forwarded to Scalar.createApiReference. Must include url or sources. |
See the Scalar configuration reference for the full list of configuration options.
The plugin merges these defaults into each instance's configuration (override per-instance as needed):
{
hideTestRequestButton: true,
hideDownloadButton: true,
hideDarkModeToggle: true,
hideClientButton: true,
hideModels: true,
showSidebar: true,
showDeveloperTools: 'never',
telemetry: false,
}- snapr.seshuk.im/api.html — live API reference rendered with this plugin.
- The plugin registers a custom page at each
routevia Rspress'saddPageshook. - Per-route configuration is attached through
extendPageData, so a single page component resolves the correct config at runtime viausePage(). - The Scalar runtime is injected as one
<script async>tag in the document head — loaded once per site, shared by all instances. theme.cssmaps Scalar's CSS variables onto Rspress's theme tokens, anduseDark()keeps the API reference in sync with the site's color scheme.
Tip
Since the Scalar bundle is loaded from a CDN at runtime, your build output stays small and the API reference picks up upstream Scalar fixes without you having to bump a dependency.
pnpm install # install deps
pnpm dev # rebuild on change
pnpm build # production build
pnpm lint # oxlint
pnpm format # oxfmt