跳至內容
Fumadocs

Bun

在 Bun 中存取內容。

設定

在預載指令碼中註冊外掛:

preload = ["./scripts/preload.ts"]

此外掛會在執行階段載入 MDX 與 meta 檔案。由於其初始化是非同步的,請務必加上 await。若未使用 await,您的指令碼會在外掛就緒前就匯入 lib/source.ts,導致 Macro API 擲出錯誤。

完成後,使用 Bun 執行任何指令碼時,您都可以直接存取內容檔案。

重新產生 .source 資料夾

您也可以視需要重新產生 .source 資料夾。

這在該資料夾可能不存在, 或您使用的是 Vite 框架 (React Router、TanStack Start、Waku) 時特別實用,因為這些框架預設會以 Vite 專屬的 API 產生程式碼。

scripts/preload.ts
import { postInstall } from 'fumadocs-mdx/next';

await postInstall({ configPath: 'source.config.ts' });

How is this guide?

最後更新於