VercelDeployer
VercelDeployerは、MastraアプリケーションをVercelにデプロイし、設定、環境変数の同期、およびデプロイプロセスを処理します。抽象Deployerクラスを拡張して、Vercel固有のデプロイ機能を提供します。
使用例
import { Mastra } from '@mastra/core';
import { VercelDeployer } from '@mastra/deployer-vercel';
const mastra = new Mastra({
deployer: new VercelDeployer({
teamSlug: 'your-team-slug',
projectName: 'your-project-name',
token: 'your-vercel-token'
}),
// ... other Mastra configuration options
});
パラメータ
コンストラクタパラメータ
teamSlug:
string
あなたのVercelチームスラッグ
projectName:
string
Vercelプロジェクトの名前(存在しない場合は作成されます)。
token:
string
あなたのVercel認証トークン。
環境変数
VercelDeployerは複数のソースからの環境変数を処理します:
- 環境ファイル:
.env.production
と.env
ファイルからの変数。 - 設定:Mastra設定を通じて渡される変数。
- Vercelダッシュボード:変数はVercelのウェブインターフェースを通じても管理できます。
デプロイヤーは、ローカル開発環境とVercelの環境変数システム間で環境変数を自動的に同期し、すべてのデプロイメント環境(本番、プレビュー、開発)間での一貫性を確保します。
Mastraプロジェクトのビルド
Vercelデプロイメント用にMastraプロジェクトをビルドするには:
npx mastra build
ビルドプロセスは.mastra/output
ディレクトリに以下の出力構造を生成します:
.mastra/output/
├── vercel.json # Vercel設定
└── index.mjs # アプリケーションのエントリーポイント
Vercel設定
VercelDeployerは自動的に.mastra/output
に以下の設定を含むvercel.json
設定ファイルを生成します:
{
"version": 2,
"installCommand": "npm install --omit=dev",
"builds": [
{
"src": "index.mjs",
"use": "@vercel/node",
"config": {
"includeFiles": ["**"]
}
}
],
"routes": [
{
"src": "/(.*)",
"dest": "index.mjs"
}
]
}
デプロイオプション
ビルド後、Mastraアプリケーションの.mastra/output
を以下のいずれかの方法でVercelにデプロイできます:
-
Vercel CLI:Vercelの公式CLIツールを使用して直接デプロイ
- CLIをインストール:
npm install -g vercel
- 出力ディレクトリに移動:
cd .mastra/output
- プレビュー環境にデプロイ:
vercel
- 本番環境へのデプロイ:
vercel --prod
- CLIをインストール:
-
Vercelダッシュボード:Gitリポジトリを接続するか、Vercelダッシュボードを通じてビルド出力をドラッグ&ドロップ
出力ディレクトリ
.mastra/output
でvercel dev
を実行して、Mastraアプリケーションをローカルでテストすることもできます。