> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # VercelDeployer `VercelDeployer` 會封裝 Mastra 伺服器,並產生符合 Vercel [Build Output API](https://vercel.com/docs/build-output-api/v3) 的輸出。Vercel 會直接將此輸出部署為 serverless function。 ## 安裝 若要使用 `VercelDeployer`,請安裝 `@mastra/deployer-vercel` 套件: **npm**: ```bash npm install @mastra/deployer-vercel@latest ``` **pnpm**: ```bash pnpm add @mastra/deployer-vercel@latest ``` **Yarn**: ```bash yarn add @mastra/deployer-vercel@latest ``` **Bun**: ```bash bun add @mastra/deployer-vercel@latest ``` ## 使用範例 匯入 `VercelDeployer`,並在 Mastra 設定中將其設為 deployer: ```typescript import { Mastra } from '@mastra/core' import { VercelDeployer } from '@mastra/deployer-vercel' export const mastra = new Mastra({ deployer: new VercelDeployer(), }) ``` ## 建構函式選項 deployer 接受下列選項: - `studio?: boolean`:將 [Studio](https://mastra.zisheng.pro/zh-TW/docs/studio/overview) 與 API 一同部署為靜態資產,由 Vercel Edge CDN 提供。預設為 `false`。 - `maxDuration?: number`:function 執行逾時時間(秒) - `memory?: number`:function 記憶體(MB) - `regions?: string[]`:要部署 function 的區域(例如 `['sfo1','iad1']`) `maxDuration`、`memory` 與 `regions` 選項會合併至 `.vercel/output/functions/index.func/.vc-config.json`,同時保留預設欄位(`handler`、`launcherType`、`runtime`、`shouldAddHelpers`)。 ### 覆寫選項範例 ```typescript import { Mastra } from '@mastra/core' import { VercelDeployer } from '@mastra/deployer-vercel' export const mastra = new Mastra({ deployer: new VercelDeployer({ studio: true, maxDuration: 600, memory: 1536, regions: ['sfo1', 'iad1'], }), }) ``` ## 建置輸出 執行 `mastra build` 後,deployer 會產生符合 Vercel [Build Output API (v3)](https://vercel.com/docs/build-output-api/v3) 的 `.vercel/output` 目錄。此目錄包含路由設定與 serverless function bundle,Vercel 會直接部署這些內容並略過框架偵測。 輸出包含: - **config.json**:將要求導向適當 handler 的路由設定 - **functions/**:封裝為 serverless function 的 Mastra 伺服器 - **static/**:Studio SPA 資產(僅在 `studio: true` 時產生) 不含 Studio: ```bash .vercel/ └── output/ ├── config.json └── functions/ └── index.func/ ├── .vc-config.json ├── index.mjs └── node_modules/ ``` 設定 `studio: true`: ```bash .vercel/ └── output/ ├── config.json ├── static/ │ ├── index.html │ └── assets/ │ ├── *.js │ └── *.css └── functions/ └── index.func/ ├── .vc-config.json ├── index.mjs └── node_modules/ ``` 啟用 Studio 時,路由會設定為由 serverless function 處理 `/api/*` 要求;靜態資產(JS、CSS)由 Vercel Edge CDN 提供,不會叫用 function;所有其他路徑則回復至 `index.html`,以進行使用者端路由。 此資料夾會在建置期間產生,不應提交至版本控制。