> ## 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.

# 使用 Next.js 和 Bun 构建应用

[Next.js](https://nextjs.org/) 是一个用于构建全栈 Web 应用的 React 框架。它支持服务端渲染、静态站点生成和 API 路由。Bun 能快速安装包，并且可以运行 Next.js 的开发和生产服务器。

***

<Steps>
  <Step title="创建新的 Next.js 应用">
    使用交互式 CLI 搭建一个新的 Next.js 项目并安装其依赖。

    ```sh terminal icon="terminal" theme={null}
    bun create next-app@latest my-bun-app
    ```
  </Step>

  <Step title="启动开发服务器">
    切换到项目目录并使用 Bun 运行开发服务器。

    ```sh terminal icon="terminal" theme={null}
    cd my-bun-app
    bun --bun run dev
    ```

    这将使用 Bun 的运行时启动 Next.js 开发服务器。

    在浏览器中打开 [`http://localhost:3000`](http://localhost:3000) 查看结果。你对 `app/page.tsx` 所做的更改会在浏览器中热重载。
  </Step>

  <Step title="更新 package.json 中的脚本">
    在你的 `package.json` 脚本中，为 Next.js CLI 命令添加 `bun --bun` 前缀，以便 Bun 执行 Next.js CLI 的 `dev`、`build` 和 `start` 命令。

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

***

## 托管

<Columns cols={3}>
  <Card title="Vercel" href="/guides/deployment/vercel" icon="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/ecosystem/vercel.svg?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=f22c4a63b7f48e2eb0d5ad3bac37f30e" width="24" height="24" data-path="icons/ecosystem/vercel.svg">
    在 Vercel 上部署
  </Card>

  <Card title="Railway" href="/guides/deployment/railway" icon="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/ecosystem/railway.svg?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=7a67ac38ee6d0dcc225a8c347cd5cc7c" width="24" height="24" data-path="icons/ecosystem/railway.svg">
    在 Railway 上部署
  </Card>

  <Card title="DigitalOcean" href="/guides/deployment/digital-ocean" icon="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/ecosystem/digitalocean.svg?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=0fc96d1d265c5b1ac1bb6212be71ea48" width="24" height="24" data-path="icons/ecosystem/digitalocean.svg">
    在 DigitalOcean 上部署
  </Card>

  <Card title="AWS Lambda" href="/guides/deployment/aws-lambda" icon="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/ecosystem/aws.svg?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=c2f1ed3fdbb52a201324e7477d667ae0" width="24" height="24" data-path="icons/ecosystem/aws.svg">
    在 AWS Lambda 上部署
  </Card>

  <Card title="Google Cloud Run" href="/guides/deployment/google-cloud-run" icon="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/ecosystem/gcp.svg?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=44ea58e5f0f27834169d1a53ce87f107" width="24" height="24" data-path="icons/ecosystem/gcp.svg">
    在 Google Cloud Run 上部署
  </Card>

  <Card title="Render" href="/guides/deployment/render" icon="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/ecosystem/render.svg?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=18e448b677536c03b75579eb8219ef5d" width="24" height="24" data-path="icons/ecosystem/render.svg">
    在 Render 上部署
  </Card>
</Columns>

***

## 模板

<Columns cols={2}>
  <Card title="Bun + Next.js 基础启动模板" img="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/images/templates/bun-nextjs-basic.png?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=33e08fa9a478c6a01fd767ddc0c5bd08" href="https://github.com/bun-templates/bun-nextjs-basic" arrow="true" cta="前往模板" width="2212" height="1326" data-path="images/templates/bun-nextjs-basic.png">
    一个使用 Bun、Next.js 和 Tailwind CSS 的简单 App Router 启动模板。
  </Card>

  <Card title="Todo 应用（Next.js + Bun）" img="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/images/templates/bun-nextjs-todo.png?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=bdac6b59796375a05897c768bd581985" href="https://github.com/bun-templates/bun-nextjs-todo" arrow="true" cta="前往模板" width="2212" height="1326" data-path="images/templates/bun-nextjs-todo.png">
    一个使用 Bun、Next.js 和 PostgreSQL 构建的全栈待办事项应用。
  </Card>
</Columns>

***

更多关于构建和部署 Next.js 应用的信息，请参考 [Next.js 文档](https://nextjs.org/docs)。
