> Discover all available pages from the documentation index: https://mastra.zisheng.pro/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/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 后,路由会配置为:`/api/*` 请求由 serverless function 处理;静态资源(JS、CSS)由 Vercel Edge CDN 提供,不会调用 function;所有其他路径均回退到 `index.html`,以进行客户端路由。 此文件夹在构建期间生成,不应提交到版本控制系统。