@clusterize/bundoc

中文文档
0.4.0发布于 2026/10/20MITES Module构建来源已验证近 30 天下载 1868

A modern bring-your-own-components documentation framework built with Bun and MDX.

原始使用文档
文档目录13 节
  1. Why bundoc
  2. Project anatomy
  3. Conventions
  4. Writing a theme
  5. MDX component overrides
  6. Public hooks
  7. Configuration
  8. Syntax highlighting
  9. Search
  10. Commands
  11. bunfig.toml plugins
  12. Status
  13. License

bundoc

A Bun-native CLI for MDX documentation sites with a bring-your-own-theme model. bundoc owns the boring parts — content discovery, MDX compile, routing, i18n, search — and exposes them as React hooks. You own every pixel of the UI.

Requires Bun ≥ 1.3. bundoc is Bun-only. It ships TypeScript source directly and uses Bun.serve / Bun.build. It will not run under Node.

bunx @clusterize/bundoc init my-docs
cd my-docs
bun install
bunx @clusterize/bundoc dev

Open http://localhost:3000.


Why bundoc

Most docs tools either lock you into a theme (Docusaurus, Mintlify) or make you wire up a Next.js project just to render Markdown (Nextra, fumadocs). bundoc sits in between:

  • Content is .mdx — frontmatter, GFM, headings, code blocks.
  • Theme is your React app — no skin system, no opinionated layout. You import a handful of hooks from bundoc/theme and render whatever you want.
  • Everything else is built in — file-system routing, i18n with fallback, build-time Orama search index, optional Shiki highlighting.

The output is a fully static SPA (bundoc build) — no server runtime, no Lambda, no edge worker. Drop dist/ on any static host.


Project anatomy

bundoc init lays this out for you:

my-docs/
├─ bundoc.config.ts        # locales, paths, mdx pipeline
├─ content/
│  ├─ index.mdx            # → /
│  ├─ index.de.mdx         # → /de
│  └─ guides/
│     ├─ _meta.json        # ordering + labels (optional)
│     └─ install.mdx       # → /guides/install
├─ public/                 # static assets copied verbatim to the site
│                          # root at build, served as-is in dev
└─ theme/
   ├─ index.tsx            # your <App/> — mounted inside bundoc providers
   └─ mdx-components.tsx   # optional: { h1, code, pre, ... }

Conventions

  • Default locale unprefixed, others prefixed: /foo vs /de/foo.
  • index.mdx is the directory's index route.
  • _meta.json in any subdir provides { order, label } overrides; otherwise alphabetical with frontmatter.title || filename.
  • Files starting with _ or . are ignored.
  • i18n filenames: install.mdx is the default-locale page; install.de.mdx is the German translation. Missing translations fall back to the default locale automatically.

Writing a theme

The theme is a regular React component. bundoc mounts it inside its providers, so the hooks "just work."

// theme/index.tsx
import {
  PageOutlet,
  Link,
  useNav,
  useCurrentPage,
  useLocale,
  useTOC,
} from "@clusterize/bundoc/theme";

export default function ThemeApp() {
  const nav = useNav();              // tree, flat, currentPath, prev, next
  const { locale, locales, setLocale } = useLocale();
  const page = useCurrentPage();     // { route, title, frontmatter, ... }
  const headings = useTOC();         // current page's h2/h3/h4

  return (
    <div className="layout">
      <aside>
        <LocaleSwitcher locales={locales} current={locale} onChange={setLocale} />
        <Sidebar tree={nav.tree} />
      </aside>
      <main>
        <h1>{page.title}</h1>
        <PageOutlet fallback={<p>Loading…</p>} />
      </main>
      <TOC items={headings} />
    </div>
  );
}

Everything is yours — styling, layout, animations, dark mode, search palette, command bar. The docs site is itself a bundoc theme; the source under packages/docs is a good full-fat reference (sidebar, sticky TOC, ⌘K search, locale switcher, dual-theme Shiki).

MDX component overrides

theme/mdx-components.tsx exports the map applied to every MDX page:

// theme/mdx-components.tsx
const components = {
  h1: (props) => <h1 className="text-3xl font-bold" {...props} />,
  a:  (props) => <a className="underline" {...props} />,
  pre: (props) => <pre className="rounded-md p-4" {...props} />,
  code: (props) => <code className="font-mono text-sm" {...props} />,
  // Custom components MDX authors can use directly inside .mdx files:
  // Callout,
};

export default components;

By default bundoc emits unstyled <pre><code class="language-ts">…</code></pre>. Style them in the override map, or enable Shiki.

Public hooks

HookWhat it returns
useNav(){ tree, flat, currentPath, prev, next } for the current locale
useCurrentPage(){ route, locale, title, frontmatter, headings, fallback, notFound }
useTOC()Heading[] from the current page (h2/h3/h4)
useLocale(){ locale, locales, defaultLocale, setLocale }
useLink()(to: string) => href — locale-aware href builder
useFrontmatter<T>()typed sugar over useCurrentPage().frontmatter
useSearchIndex()lazy client that queries the build-time Orama index
<Link to=… />locale-aware <a> wrapper
<PageOutlet />the slot where the current MDX page renders

The router and providers are runtime-owned; theme code only consumes hooks. This keeps the contract stable across future CSR → SSR work.


Configuration

bundoc.config.ts:

import { defineConfig } from "@clusterize/bundoc/config";

export default defineConfig({
  locales: ["en", "de"],
  defaultLocale: "en",
  contentDir: "./content",          // default
  themeEntry: "./theme/index.tsx",  // default
  basePath: "/",                    // for hosting under a subpath
  mdx: {
    highlighting: { light: "github-light", dark: "github-dark" },
  },
  search: {
    // Honour `search: false` in frontmatter. Replace or extend
    // for route-prefix exclusion, draft filtering, etc.
    filter: (page) => page.frontmatter.search !== false,
  },
});

Syntax highlighting

Off by default. Set mdx.highlighting: true (or pass theme names) to turn on build-time Shiki with dual light/dark CSS variables. Toggle the active theme via an html.dark class on your root — your theme decides when to apply it.

Always on. At build time bundoc walks every MDX, extracts the plaintext, and writes one Orama BM25 index per locale to dist/_bundoc/search/<locale>.json. useSearchIndex() lazy-fetches it client-side. No server, no API key, no third party.

Inclusion is governed by search.filter in bundoc.config.ts. The default predicate honours frontmatter.search !== false — pass your own to exclude by route prefix, locale, draft flag, or any combination. The predicate signature is exported as SearchablePage and the default as defaultSearchFilter, so you can extend rather than replace it.


Commands

CommandWhat it does
bundoc devDev server with HMR on localhost:3000.
bundoc buildStatic site to dist/.
bundoc previewServe dist/ with SPA fallback.
bundoc pdfPDF handbook per locale to dist/_bundoc/pdf/ (needs Playwright).
bundoc init <dir>Scaffold a new project.

Flags: --port, --host, --out, --locale. Run bundoc --help.

bunfig.toml plugins

Anything you put under [serve.static].plugins applies to both bundoc dev and bundoc build — useful for Tailwind, PostCSS, etc.


Status

bundoc is pre-1.0. The hooks listed above are stable; internals are not. The full reference and roadmap live at bundoc.dev.

License

MIT — see LICENSE.

版本与发布记录

@clusterize/bundoc 共发布 8 个版本,首次发布于 2026/05/13;过去 12 个月发布了 8 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.0latest2026/10/2021 天前
0.3.22026/06/015 个月前
0.3.12026/05/275 个月前
0.2.32026/05/185 个月前
0.2.22026/05/165 个月前
0.2.12026/05/165 个月前

关于 @clusterize/bundoc 的常见问题

@clusterize/bundoc 是什么?

A modern bring-your-own-components documentation framework built with Bun and MDX.

如何安装 @clusterize/bundoc?

在项目目录运行 npm install @clusterize/bundoc,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.0.0)、react-dom(^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 bundoc,可以用 npx bundoc 直接运行。

@clusterize/bundoc 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/clusterize__bundoc 是否存在。

@clusterize/bundoc 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@clusterize/bundoc 可以商用吗?

@clusterize/bundoc 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@clusterize/bundoc 的下载量有多少?

根据 npm 官方下载统计,@clusterize/bundoc 在 2026/10/10 – 2026/11/08 这 30 天内被下载 1,868 次,日均约 62 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@clusterize/bundoc 还在维护吗?

最新版本 0.4.0 发布于 2026/10/20(21 天前);至今共发布 8 个版本,其中过去 12 个月发布了 8 个;首次发布于 2026/05/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。