> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # VercelDeployer `VercelDeployer` 會封裝你的 Mastra 伺服器,並產生符合 Vercel [Build Output API](https://vercel.com/docs/build-output-api/v3) 的輸出。Vercel 會直接將此輸出部署為無伺服器函式。 ## 安裝 要使用 `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-HK/docs/studio/overview) 與 API 一併部署為由 Vercel Edge CDN 提供的靜態資源。預設為 `false`。 - `maxDuration?: number`:函式執行逾時時間(秒) - `memory?: number`:函式記憶體(MB) - `regions?: string[]`:部署函式的區域(例如 `['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` 目錄。該目錄包含路由設定及無伺服器函式套件,Vercel 會略過框架偵測並直接部署這些內容。 輸出包含: - **config.json**:將請求導向適當 handler 的路由設定 - **functions/**:封裝為無伺服器函式的 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 後,路由會設定為由無伺服器函式處理 `/api/*` 請求;靜態資源(JS、CSS)則由 Vercel Edge CDN 提供,不會調用函式;所有其他路徑都會回退至 `index.html`,以便在客戶端處理路由。 此資料夾會在建置期間產生,不應提交至版本控制系統。