> ## Documentation Index
> Fetch the complete documentation index at: https://bun.ll1025.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 在 Vercel 上部署 Bun 应用

[Vercel](https://vercel.com/) 是一个用于构建、部署和扩展应用程序的云平台。

<Warning>
  Bun 运行时处于 Beta 阶段。某些功能尚不支持——例如，自动源码映射、字节码缓存和 `node:http/https` 上的指标。
</Warning>

<Note>
  `Bun.serve` 在 Vercel Functions 上不受支持。请将 Bun 与 Vercel 支持的框架一起使用，如 Next.js、Express、Hono 或 Nitro。
</Note>

***

<Steps>
  <Step title="在 vercel.json 中配置 Bun">
    要为你的 Functions 启用 Bun 运行时，请在 `vercel.json` 文件中添加 `bunVersion` 字段：

    ```json vercel.json icon="file-json" theme={null}
    {
    	"bunVersion": "1.x" // [!code ++]
    }
    ```

    Vercel 会自动检测此配置并在 Bun 上运行你的应用程序。该值必须为 `"1.x"`；Vercel 会在内部处理次要版本。

    为获得最佳效果，请将你的本地 Bun 版本与 Vercel 使用的版本保持一致。
  </Step>

  <Step title="Next.js 配置">
    如果你要部署 **Next.js** 项目（包括 ISR），请更新你的 `package.json` 脚本以使用 Bun 运行时：

    ```json package.json icon="file-json" theme={null}
    {
    	"scripts": {
    		"dev": "bun --bun next dev", // [!code ++]
    		"build": "bun --bun next build" // [!code ++]
    	}
    }
    ```

    <Note>
      `--bun` 标志使 Next.js CLI 在 Bun 下运行。打包（使用 Turbopack 或 Webpack）不变。
    </Note>

    使用这些脚本后，本地开发和构建都将使用 Bun。
  </Step>

  <Step title="部署你的应用">
    将你的仓库连接到 Vercel，或从 CLI 部署：

    ```bash terminal icon="terminal" theme={null}
    # 使用 bunx（无需全局安装）
    bunx vercel login
    bunx vercel deploy
    ```

    或者全局安装 Vercel CLI：

    ```bash terminal icon="terminal" theme={null}
    bun i -g vercel
    vercel login
    vercel deploy
    ```

    [了解更多 → Vercel Deploy CLI 文档](https://vercel.com/docs/cli/deploy)
  </Step>

  <Step title="验证运行时">
    要确认你的部署使用了 Bun，请打印 Bun 版本：

    ```ts index.ts icon="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/typescript.svg?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=787d39d6a7d96d7f9540dc74344eba23" theme={null}
    console.log("runtime", process.versions.bun);
    ```

    ```txt theme={null}
    runtime 1.3.3
    ```

    [查看 Vercel Bun 运行时文档了解功能支持 →](https://vercel.com/docs/functions/runtimes/bun#feature-support)
  </Step>
</Steps>

***

* [Fluid compute](https://vercel.com/docs/fluid-compute)：Bun 和 Node.js 运行时都运行在 Fluid compute 上，并支持相同的基础 Vercel Functions 功能。
* [中间件](https://vercel.com/docs/routing-middleware)：要使用 Bun 运行路由中间件，将运行时设置为 `nodejs`：

```ts middleware.ts icon="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/typescript.svg?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=787d39d6a7d96d7f9540dc74344eba23" theme={null}
export const config = { runtime: "nodejs" }; // [!code ++]
```
