VitePress integration
The frappe-ui/vitepress package entry provides a shared VitePress experience for documentation sites. It joins a Vue runtime surface for layouts and documentation UI with a Node configuration surface that assembles site settings, content helpers, and build support.
Integration surface
The integration has separate runtime and configuration roles behind one package subpath. VitePress loads the Node side while it reads a site config. Vue code loads the browser/SSR side for the rendered theme. The package export map selects the role by context, while its type entry presents both surfaces to editors. (See the related build and framework integration page and Vite plugins and generators page.)
| Consumer context | Main capability | Entry behavior |
|---|---|---|
| Vue runtime | Shared docs theme, layouts, docs widgets, sidebar helpers, and shared UI state | frappe-ui/vitepress resolves to the runtime barrel |
| VitePress Node config | Site config builder, content transforms, colocated-doc helpers, sidebar helpers, and build chunk safety | The node export condition resolves to the Node entrypoint |
| TypeScript editor | One view of both named API surfaces | The types condition combines the runtime and Node declarations |
The subpath is an unstable integration surface. It is intended for supported documentation-site use rather than product application code, so consumers must expect its shape to change without the normal compatibility window. References: package.json• L85-89, vitepress/index.ts• L1-20, vitepress/index.node.ts• L1-10, vitepress/index.d.ts• L1-17
Runtime theme
The runtime theme gives a VitePress site a shared visual and documentation layer. It supplies the main layout and reusable documentation widgets such as component previews, property tables, slot tables, event tables, playground frames, search, navigation, and command-palette UI. It also exposes site-wide actions for an optional repository link and a light, dark, or system color scheme. Importing the theme also brings in its stylesheet, so the theme is the main runtime starting point rather than a collection of unrelated widgets.
The runtime barrel also exposes the shared layout components, site actions, sidebar link helpers, sidebar types, and reactive state used by the docs UI. A consuming site can use the complete theme or compose selected pieces around its own VitePress layout. References: vitepress/index.ts• L8-20, vitepress/…/index.ts• L1-24, vitepress/…/index.ts• L1-5, vitepress/…/SiteActions.vue• L1-27, vitepress/…/SiteActions.vue• L29-67, vitepress/…/index.ts• L1-15, vitepress/state.ts• L1-10
Theme adoption
The normal theme flow starts with the site theme entry. It imports the shared theme, then exports it directly or extends it with site-specific layout behavior. The repository's own docs site follows this model and adds its marketing layout and a router for components that expect Vue Router links.
This diagram shows how a VitePress page receives the shared theme and how a site can add local behavior without replacing the shared docs layer.
flowchart LR
A[VitePress theme entry] --> B[frappe-ui/vitepress runtime theme]
B --> C[Shared layout and docs widgets]
A --> D[Site-specific layout and app setup]
C --> E[Rendered documentation page]
D --> E
The runtime theme is for the browser and SSR side of VitePress. The Node config entry must not be used as a Vue theme because it includes configuration-time helpers and does not expose Vue single-file components.
References: vitepress/index.ts• L1-20 vitepress/…/index.ts• L1-24 docs/…/index.ts• L1-30
Node configuration
The Node entrypoint exposes defineDocsConfig, a config builder that turns site identity, navigation, and optional content settings into a VitePress configuration. It establishes the content root, clean URLs, last-updated data, code highlighting, local search, site metadata, aliases, server access, server-rendering rules, and build safeguards as one consistent site baseline.
The builder keeps site-specific information in the caller while it supplies shared behavior. The caller provides a docs root, site name, description, sidebar tree, and optional branding or extension hooks. Optional source roots and colocated-doc settings connect component source to documentation pages when a site needs that feature. References: vitepress/index.node.ts• L30-64, vitepress/index.node.ts• L118-171, vitepress/index.node.ts• L201-236
Configuration inputs
The configuration contract separates required site identity from optional integration features. This lets a general documentation site use the shared baseline without adopting the repository's component-doc workflow.
| Input group | Role |
|---|---|
| Site identity | Sets the root, name, description, base URL, version, logo, and GitHub link |
| Navigation | Supplies the sidebar tree rendered by the shared navigation UI |
| Content integration | Adds source roots, component markdown transforms, and optional colocated documentation |
| Site extension | Adds aliases, head tags, and extra Markdown configuration |
The Node entrypoint also re-exports sidebar types and link helpers. It re-exports the content plugins so a site can opt into those capabilities directly when the higher-level config builder is not enough.
References: vitepress/index.node.ts• L33-64 vitepress/index.node.ts• L239-250 vitepress/…/index.ts• L1-12
Build output safety
The shared build setup pre-bundles dependencies pulled in by the common theme so development startup does not trigger repeated dependency optimization reloads. It keeps framework code and editor core code in stable shared chunks. It also checks the final output for a framework-to-theme dependency cycle, because that cycle can fail page startup before the theme is ready. This protects both normal VitePress pages and pages that load the code editor or other shared Vue packages.
The safeguard is part of the Node configuration path. Sites that use defineDocsConfig receive the same startup dependency set, chunk layout, and a build error when the output still contains the unsafe dependency direction. Page-specific heavy dependencies remain local to the pages that use them. References: vitepress/…/preventCircularChunks.ts• L3-26, vitepress/…/preventCircularChunks.ts• L34-69, vitepress/index.node.ts• L66-102, vitepress/index.node.ts• L170-198
Documentation content flow
The integration connects source content to VitePress in two levels. The config builder sets the normal Markdown and page environment. Optional content tools then enrich Markdown with component examples and can create proxy pages for documentation stored next to source components.
Component content tags use the configured source roots to find the story, type, or playground source that backs a page. The transformer turns those tags into rendered Vue content plus source snippets. If a site does not configure source roots, the component tags are left in place and the integration warns instead of guessing a legacy path.
When the colocated-doc option is enabled, a site first seeds proxy pages before VitePress scans its content directory. The Vite plugin then keeps those proxies aligned during development. This allows source-adjacent docs to appear in the site's normal navigation without requiring every page to be copied by hand.
This diagram shows the supported path from site configuration and source roots to rendered documentation.
flowchart TD
A[Site config] --> B[defineDocsConfig]
C[Configured source roots] --> D[Component content tools]
B --> E[VitePress content environment]
D --> E
E --> F[Markdown pages and component demos]
F --> G[Shared runtime theme]
G --> H[Documentation site]
The repository's docs site uses the separate sync step to seed colocated pages, then passes the same source-root map to the config builder for live updates. This pattern is useful when source code and its docs must move together. References: vitepress/index.node.ts• L151-159, vitepress/index.node.ts• L184-190, vitepress/…/componentTransformer.ts• L17-46, vitepress/…/componentTransformer.ts• L264-337, vitepress/…/index.ts• L1-12, docs/…/config.ts• L18-26, docs/…/config.ts• L150-190
Export selection
The package uses export conditions to keep Node configuration code away from the browser bundle and Vue components away from the Node config loader. TypeScript uses a combined declaration file because editor resolution does not otherwise apply the same runtime condition split.
At runtime, the default entry serves Vue code and the node entry serves VitePress configuration code. At type-check time, the combined declaration makes both named surfaces visible without changing which code runs. References: package.json• L85-89, vitepress/index.d.ts• L1-27
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the package export conditions aligned with the runtime and Node entrypoints. A mismatch can make a Node config load Vue code or make a browser build load Node code.
- Keep vitepress/index.d.ts aligned with both runtime barrels. Otherwise editor types can disagree with the entrypoint selected at runtime.
- Keep the shared sidebar data shape aligned with
DefineDocsConfigOptions.sidebarand the runtime navigation components. - When changing source-root or colocated-doc behavior, check both the initial proxy sync and the development Vite plugin path. The roots used by Markdown transforms must also point to the source files used for snippets and demos.
- When changing theme components or browser aliases, verify that the Node config remains free of Vue single-file component imports.
- When changing shared theme dependencies, keep the Node entrypoint's dependency pre-bundle list aligned with the packages used by the theme. Do not add page-specific heavy dependencies to the common startup set.
- When changing dependency chunk rules, check that framework code does not import the theme chunk and that editor core keeps one shared class identity across full and lean page chunks.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A consumer imports the Node-only surface from browser or SSR code | Vue theme features are unavailable or Node-only modules enter the client graph | Use the default runtime entry for Vue code and reserve the node condition for VitePress config loading |
| The type declaration omits a newly exported runtime or Node name | Editors reject a valid import or suggest an incomplete API | Update the combined index.d.ts surface with each public export change |
| A site enables component content tags without valid source roots | Previews, type snippets, or playgrounds do not resolve | Pass source roots that contain the component stories, types, and playground files |
| A site enables colocated docs without valid source and proxy roots | Component pages are not seeded or do not track their source docs | Pass matching absolute source roots and proxy directories to the sync and watcher paths |
| A sidebar tree does not match the shared sidebar data contract | Navigation is incomplete or the shared sidebar cannot render the supplied sections | Treat the sidebar type and the runtime sidebar as one contract |
| The common dependency pre-bundle list names a package that the site does not install | VitePress config loading or development startup fails before pages render | Keep the list limited to dependencies used by the shared theme and present in the package's supported dependency set |
| The build leaves a framework-to-theme chunk edge | The page can fail during module initialization with a temporal-dead-zone error | Keep shared Vue ecosystem packages in the framework boundary and let the build check reject the cycle |
| The build duplicates editor core classes across page chunks | Editor extensions can reject values from a different class copy | Keep editor core in one shared chunk while language grammars remain lazy |
| A site treats the unstable subpath as a frozen product API | A package update can break the site without a deprecation period | Keep usage within supported documentation sites and review the entrypoint on package upgrades |
Key files
| File | Why to read it |
|---|---|
| package.json | Defines the frappe-ui/vitepress export conditions and the files included in the package |
| vitepress/index.ts | Shows the browser and SSR runtime surface |
| vitepress/index.node.ts | Defines the Node config builder and Node-side content and build exports |
| vitepress/index.d.ts | Explains the combined TypeScript view of both entrypoints |
| vitepress/…/index.ts | Shows the shared theme composition and global docs components |
| vitepress/…/SiteActions.vue | Shows the shared repository link and color-scheme controls exposed by the runtime surface |
| vitepress/…/index.ts | Shows the reusable documentation UI surface |
| vitepress/…/index.ts | Shows the optional Markdown and colocated-doc tooling surface |
| vitepress/…/componentTransformer.ts | Explains how component examples and source snippets connect to configured source roots |
| vitepress/…/preventCircularChunks.ts | Explains the build boundary and checks that prevent unsafe VitePress chunk graphs |
| docs/…/config.ts | Demonstrates how an application documentation site supplies the shared config inputs |
| docs/…/index.ts | Demonstrates extending the shared runtime theme with site-specific behavior |