# Fumadocs MDX (the built-in content source): Bun
URL: /zh-TW/docs/mdx/loader/bun
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/mdx/(integrations)/loader/bun.zh-TW.mdx

在 Bun 中存取內容。

## 設定 [#setup]

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

```toml tab="bunfig.toml"
preload = ["./scripts/preload.ts"]
```

```ts tab="scripts/preload.ts"
import { createMdxPlugin } from 'fumadocs-mdx/bun';

await Bun.plugin(createMdxPlugin());
```

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

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

### 重新產生 `.source` 資料夾 [#re-generate-source-folder]

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

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

```ts title="scripts/preload.ts" tab="Next.js"
import { postInstall } from 'fumadocs-mdx/next';

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

```ts title="scripts/preload.ts" tab="Vite"
import { postInstall } from 'fumadocs-mdx/vite';

await postInstall({
  configPath: 'source.config.ts',
  index: {
    target: 'bun',
  },
});
```