Bun

指南生態系統

使用 Next.js 和 Bun 建立應用程式

Next.js 應用程式路由器目前依賴於 Bun 尚未實作的 Node.js API。以下指南使用 Bun 初始化專案並安裝相依性,但使用 Node.js 執行開發伺服器。

使用 create-next-app 初始化 Next.js 應用程式。這會自動使用 npm 安裝相依性。

bun create next-app
✔ What is your project named? … my-app
✔ Would you like to use TypeScript with this project? … No / Yes
✔ Would you like to use ESLint with this project? … No / Yes
✔ Would you like to use `src/` directory with this project? … No / Yes
✔ Would you like to use experimental `app/` directory with this project? … No / Yes
✔ What import alias would you like configured? … @/*
Creating a new Next.js app in /path/to/my-app.

要使用 Bun 啟動開發伺服器,請從專案根目錄執行 bun --bun run dev

cd my-app
bun --bun run dev

要改用 Node.js 執行開發伺服器,請省略 --bun

cd my-app
bun run dev

使用瀏覽器開啟 https://127.0.0.1:3000 以查看結果。對 (pages/app)/index.tsx 所做的任何變更都將在瀏覽器中熱重載。