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プロジェクトのリント
Mastraプロジェクトをリントして、ビルドに問題がないことを確認します
npx mastra lint
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アプリケーションをローカルでテストすることもできます。