VercelDeployer
VercelDeployer は Mastra サーバーをバンドルし、Vercel の Build Output API に準拠した出力を生成します。Vercel はこの出力をサーバーレス関数として直接デプロイします。
インストールインストールへの直接リンク
VercelDeployer を使用するには、@mastra/deployer-vercel パッケージをインストールします。
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/deployer-vercel@latest
pnpm add @mastra/deployer-vercel@latest
yarn add @mastra/deployer-vercel@latest
bun add @mastra/deployer-vercel@latest
使用例使用例への直接リンク
VercelDeployer をインポートし、Mastra 設定で deployer に指定します。
import { Mastra } from '@mastra/core'
import { VercelDeployer } from '@mastra/deployer-vercel'
export const mastra = new Mastra({
deployer: new VercelDeployer(),
})
コンストラクターオプションコンストラクターオプションへの直接リンク
deployer は次のオプションを受け取ります。
studio?: boolean:API とともに Studio を、Vercel の Edge CDN から配信される静的アセットとしてデプロイします。デフォルトはfalseです。maxDuration?: number:関数の実行タイムアウト(秒)memory?: number:関数のメモリ(MB)regions?: string[]:関数をデプロイするリージョン(例:['sfo1','iad1'])
maxDuration、memory、regions オプションは、デフォルトフィールド(handler、launcherType、runtime、shouldAddHelpers)を保持したまま .vercel/output/functions/index.func/.vc-config.json にマージされます。
オーバーライドの例オーバーライドの例への直接リンク
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) に準拠した .vercel/output ディレクトリを生成します。このディレクトリには、Vercel がフレームワーク検出を介さずに直接デプロイするルーティング設定とサーバーレス関数バンドルが含まれます。
出力には次のものが含まれます。
- config.json:リクエストを適切なハンドラーへ振り分けるルーティング設定
- functions/:サーバーレス関数としてバンドルされた Mastra サーバー
- static/:Studio SPA のアセット(
studio: trueの場合のみ)
Studio を含めない場合:
.vercel/
└── output/
├── config.json
└── functions/
└── index.func/
├── .vc-config.json
├── index.mjs
└── node_modules/
studio: true の場合:
.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 へフォールバックするよう設定されます。
このフォルダーはビルド時に生成されるため、バージョン管理にコミットしないでください。