Skip to content
packages

@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

SubpathContents
.docvia, the Vite plugin; defineConfig; the DocviaVitePluginOptions type.
./package.jsonPackage 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.

vite.config.ts
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):

src/lib/source.ts
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 the components in 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.noExternal and optimizeDeps.include for you.

See Framework integration for SvelteKit, React + Vite and TanStack Start walkthroughs.

Legacy config collections. Collections declared in docvia.config.ts are still served as virtual:docvia/source and virtual:docvia/registry, with types written to .docvia/*.d.ts in dev.

See also