API/vike-plugin-typedoc

vike-plugin-typedoc

Headless TypeDoc integration for Vike docs sites — parser, navigation, and context API

npm install vike-plugin-typedoc
v0.3.0NPMGitHub

vike-plugin-typedoc

Headless TypeDoc integration for Vike documentation sites.

Installation

npm install vike-plugin-typedoc

Peer dependencies:

  • vike >= 0.4.250
  • vike-react >= 0.5 (if you use the React hooks)
  • react >= 18 (if you use the React hooks)

What It Does

  • Loads TypeDoc JSON files into a cached TypedocContext.
  • Builds package and symbol URLs (default /api/:pkg/:symbol).
  • Builds API navigation trees.
  • Pre-renders markdown fields and auto-links type references.
  • Provides Vike data helpers (withApiPackage, withApiExport) and React hooks (useApiPackage, useApiExport).
  • Provides a Vike config extension that auto-loads context and prerender URLs.

Quick Start

Add the plugin extension and typedoc config:

import { join } from 'node:path';
import vikePluginTypedoc from 'vike-plugin-typedoc/config';
import vikeReact from 'vike-react/config';
import type { Config } from 'vike/types';

const root = process.cwd();

export default {
  extends: [vikeReact, vikePluginTypedoc],
  prerender: true,
  typedoc: {
    typedocDir: join(root, '.typedoc'),
    packagesDir: join(root, 'packages'),
    basePath: '/api',
  },
} satisfies Config;

The plugin expects one TypeDoc JSON file per package slug in typedocDir (for example .typedoc/devkit.json).

Package and Symbol Pages

Package route data loader:

// pages/api/@pkg/+data.ts
import { withApiPackage } from 'vike-plugin-typedoc/server';
import type { PageContextServer } from 'vike/types';

export function data(pageContext: PageContextServer) {
  return withApiPackage(pageContext, pageContext.routeParams.pkg);
}

Package route component:

// pages/api/@pkg/+Page.tsx
import { useApiPackage } from 'vike-plugin-typedoc/client';

export default function Page() {
  const { apiPackage, packageName } = useApiPackage();
  if (!apiPackage) return <h1>Package not found: {packageName}</h1>;
  return <h1>{packageName}</h1>;
}

Symbol route data loader:

// pages/api/@pkg/@symbol/+data.ts
import { withApiExport } from 'vike-plugin-typedoc/server';
import type { PageContextServer } from 'vike/types';

export function data(pageContext: PageContextServer) {
  const { pkg, symbol } = pageContext.routeParams;
  return withApiExport(pageContext, pkg, symbol);
}

Symbol route component:

// pages/api/@pkg/@symbol/+Page.tsx
import { useApiExport } from 'vike-plugin-typedoc/client';

export default function Page() {
  const { apiExport, packageName } = useApiExport();
  if (!apiExport) return <h1>Symbol not found in {packageName}</h1>;
  return <h1>{apiExport.name}</h1>;
}

typedoc Config Options

OptionTypeDescription
typedocDirstringDirectory containing *.json TypeDoc output files.
packageNamesRecord<string, string>Optional slug-to-npm-name overrides.
packagesDirstringReads missing package names from <packagesDir>/<slug>/package.json.
excludestring[]Package slugs to skip when loading docs.
buildUrl(packageSlug: string, symbolSlug?: string) => stringCustom URL builder for package and symbol pages.
basePathstringPrefix used by default URL builder. Defaults to /api.
baseUrlstringDeployment base URL used when generating HTML links.
remarkPluginsPluggableListExtra remark plugins for markdown rendering.
rehypePluginsPluggableListExtra rehype plugins for markdown rendering (for example syntax highlighting).

Server and Client Entrypoints

  • vike-plugin-typedoc/server:
    • loadTypedocContext()
    • getTypedocContext()
    • withApiPackage()
    • withApiExport()
  • vike-plugin-typedoc/client:
    • useApiPackage()
    • useApiExport()

Headless Utilities (Without Vike Hooks)

Root exports are usable even outside Vike page hooks:

import {
  buildApiNavigation,
  buildMarkdownProcessor,
  buildSymbolsMap,
  combineApiDocs,
  createTypedocContext,
  parseTypedocJson,
} from 'vike-plugin-typedoc';

This is useful if you want to parse TypeDoc JSON once and feed another renderer, while reusing the same symbol-linking logic.

License

MIT

API EXPORTS

Functions

buildApiNavigationfunction

Build navigation items for the sidebar from API docs. Groups exports by package, with individual export links as children. When `singlePackage` is true and exactly one package exists, the navigation is flattened: export items appear at the top level without a package grouping node.

buildMarkdownProcessorfunction

Build a unified processor for rendering markdown to HTML. The pipeline is: remarkParse -> remarkGfm -> remarkBreaks -> remarkDirective -> remarkCodeProps -> [user remarkPlugins] -> remarkRehype -> [rehypeTypedoc] -> [user rehypePlugins] -> [rehypeTypedocCodeBlocks] -> rehypeStringify If no rehype-typedoc options are provided, the typedoc plugins are skipped.

codeToHtmlfunction

Render code to HTML using Shiki.

combineApiDocsfunction

Combine multiple package API docs into a unified `ApiDocs` structure.

createTypedocContextfunction

Create a TypedocContext from pre-parsed packages. This is the low-level API -- use `loadTypedocContext` for the common case of loading TypeDoc JSON files from disk. The function is async because it eagerly pre-renders all markdown fields (descriptions, remarks, examples) through a unified pipeline so that `getLinkedExport()` can return fully-rendered HTML synchronously.

deserializeTypedocJsonfunction

Deserialize TypeDoc JSON using TypeDoc's native `Deserializer.reviveProject()` and walk the resulting `ProjectReflection` to produce an `ApiPackage` and a side-channel map from each `ApiExport` to its raw TypeDoc `Type`.

renderExportMarkdownfunction

Pre-render all markdown fields of an export's comment. Note: Signature rendering is handled by the type-renderer pipeline, not by the markdown processor. - `summary` is rendered as-is (inline markdown) - `remarks` is rendered as-is (block markdown) - Each example is wrapped in a typescript code fence before rendering (produces syntax-highlighted `<pre><code>` blocks)

renderSignatureToHtmlfunction

Render a pre-built signature string with ranges to syntax-highlighted HTML. Takes a plain text signature and its ranges (e.g., from `typeToStringWithRanges`), applies optional prettier formatting + Shiki tokenization + range merging, and returns an HTML string.

renderTypeToHtmlfunction

Render a TypeDoc `Type` to syntax-highlighted HTML with linked references. Pipeline: 1. Walk the type tree → plain string + range map 2. Optionally format with prettier 3. Tokenize with Shiki 4. Merge tokens with ranges → HTML with `<a>` links

slugifyfunction

Convert camelCase/PascalCase to kebab-case for URL slugs.

tokenizefunction

Tokenize TypeScript code using Shiki. Returns themed tokens with character-level offset information.

typeToStringWithRangesfunction

Walk a TypeDoc `Type` tree, producing a plain string representation and a parallel array of ranges that map symbol names to URL paths.