Documentation plugin
Docs gives a package a VitePress site, embedded in your Vite dev server and built with your library. The API reference comes from the TypeDoc plugin (@mrmt/unplugin-typedoc), the sidebar from @mrmt/vitepress-plugin-sidebar.
How it works
There are two complementary pieces:
Docs— a Vite plugin (included inLibby default) that scaffolds a VitePress site and embeds its dev server into your main Vite dev server.TypeDocPlugin— a Vite (and Rolldown) plugin, from@mrmt/unplugin-typedoc, added to your mainvite.config.tsthat generates Markdown from your source files' JSDoc comments (included inLibby default).
Dev mode
When you run vite dev, the docs are served at http://localhost:5173/docs/ alongside your main app — no separate terminal needed. TypeDoc (see above) also runs in watch mode, so the API reference stays up-to-date as you edit source files.
Production build
When you run vite build, TypeDoc runs first, then VitePress is built automatically as part of the process.
Default scaffolded files
The first time Docs runs it writes these files (only if they don't exist):
| File | Type | Description |
|---|---|---|
docs/index.md | Default | Home page with hero section |
docs/.vitepress/config.ts | Default | VitePress config with auto-sidebar |
docs/.vitepress/theme/index.ts | Default | Theme with sidebar indentation CSS |
docs/.gitignore | Default | Ignores VitePress build artifacts |
Default files are written once. Delete them to regenerate.
Configuring the docs plugin
// vite.config.ts
import { Lib } from "@mrmt/vite/lib";
export default defineConfig({
plugins: Lib({
// Serve docs at a different path (must start and end with /)
docs: { serve: "/documentation/" },
// Or disable the docs plugin entirely
docs: false,
}),
});If you're not using Lib, add Docs directly:
import { Docs } from "@mrmt/vite/docs";
export default defineConfig({
plugins: [Docs()],
});Monorepo mode
In a monorepo where every package keeps its docs next to its code (packages/<pkg>/docs/), scaffold one site assembling all of them. Put Docs in the root vite.config.ts with workspace: true:
// vite.config.ts (monorepo root)
import { Docs } from "@mrmt/vite/docs";
export default defineConfig({
plugins: [Docs({ workspace: true })],
});The first run writes the same default files as above, with two differences:
docs/.vitepress/config.tscallsworkspaceDocs()instead of the single-siteSidebar()plugin, so each package with markdown in itsdocs/folder is served at/<package directory name>/, with a Packages nav dropdown, a sidebar per package, and relative.mdlinks working across packages. Pass options (order,shell,restart, …) toworkspaceDocs()in that file: it is a default file, so it is yours to edit.docs/index.mdhas no "API Reference" button, since there is no single API reference to point at.
Notes:
- The root
package.jsonneeds"type": "module", like the single-package site: the config imports ESM-only packages. vite devmounts the docs at/docs/as usual. A monorepo root has no bundle entry, so build the site withvitepress build docsrather thanvite build.- Add
@mrmt/vitepress-plugin-sidebarandvitepressto the root's dev dependencies.