@docvia/build/vite
The docvia() Vite plugin: compiles defineDocs() collections and Markdown pages on demand, with HMR.
On this page
@docvia/build/vite integrates docvia into any Vite-based app (SvelteKit,
React + Vite, TanStack Start). docvia() is its only plugin. It rewrites
defineDocs() / defineRegistry() calls at build time and compiles each page in
memory when it is first loaded, so there is no separate docvia build step and no
.docvia/ folder.
pnpm add -D @docvia/build
pnpm add @docvia/core
vite (^8) and @docvia/core/source are peer dependencies. The generated code
imports @docvia/core/source, so the plugin fails at startup with a CONFIG_ERROR
when your app cannot resolve it.
Requires Node.js >=20.0.0. ESM only.
Package exports
| Subpath | Contents |
|---|---|
. | docvia, the Vite plugin; defineConfig; the DocviaVitePluginOptions type. |
./package.json | Package metadata. |
docvia()
function docvia(config?: docviaConfig, options?: DocviaVitePluginOptions): Plugin;
interface DocviaVitePluginOptions {
configPath?: string | false; // relative to the Vite root; auto-detected
}
Called with no config, docvia() loads docvia.config.* from the Vite root and
restarts the dev server when it changes. Passing a config object also works.
import { docvia } from "@docvia/build/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [docvia()], // loads ./docvia.config.ts
});
In SvelteKit, add it alongside sveltekit(). Then declare the collection in any
module (every non-node_modules file that imports @docvia/core/source/macro is
transformed):
import { loader } from "@docvia/core/source";
import { defineDocs } from "@docvia/core/source/macro";
const docs = defineDocs({ dir: "content/docs" });
export const source = loader({ baseUrl: "/docs", source: docs.toDocviaSource() });
What the plugin does:
- Macro transform.
defineDocs()becomes an index of the folder's frontmatter plus a lazy import per page body.defineRegistry()becomes real imports of thecomponentsin your config. - On-demand compile. A page body compiles when
page.data.load()first imports it, in memory, keyed by content hash. - HMR. A body edit hot-swaps that page. Frontmatter edits, adds and deletes re-index the collection and reload, with no dev-server restart. Collection directories outside the Vite root are watched too. Compile errors surface in Vite's error overlay.
- Dependency config. The renderer's runtime package is added to
ssr.noExternalandoptimizeDeps.includefor you.
See Framework integration for SvelteKit, React + Vite and TanStack Start walkthroughs.
Legacy config collections. Collections declared in
docvia.config.tsare still served asvirtual:docvia/sourceandvirtual:docvia/registry, with types written to.docvia/*.d.tsin dev.
See also
@docvia/core/source:defineDocs()andloader().@docvia/build: the page pipeline the plugin runs.