0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Vercelで環境変数を設定する方法 - Production / Preview / Development +ブランチ別設定

Last updated at Posted at 2025-02-28

Vercelでは、Production(本番) / Preview(プレビュー) / Development(開発) の3つに分けて環境変数を設定できます。
たとえば、Supabaseのブランチング機能で複数のDBを用意している場合、ブランチごとに接続先を切り替えたいことがありますが、VercelのPreview環境ならブランチ単位で環境変数を設定できるため、こうした運用にとても便利です。

手順:Environment Variables 設定画面

  1. Vercelのダッシュボードでプロジェクトを開く
  2. SettingsEnvironment Variables をクリック
  3. Environments から Production, Preview, Development のいずれかを選択
  4. KeyValue を入力
  5. Save を押して登録

スクリーンショット 2025-02-28 142655.png
スクリーンショット 2025-02-28 142734.png
image.png

Preview環境のブランチ別設定

「Environments」で Preview を選んだあとに、ブランチ名(例:feature/hoge など)を追加指定することで、特定のブランチだけ別の値を上書きできます。

例えば「Preview環境のデフォルト値」と、「feature/payment ブランチでのみ使う値」を分けることが可能です。複数のブランチに対して、それぞれ独自の値をセットすることもできます。
スクリーンショット 2025-02-28 142903.png

まとめ

  • Production / Preview / Development の3つの環境に分けて環境変数を管理可能
  • Preview環境ではブランチ名を指定して、ブランチごとに異なる値を設定できる
  • 手順は Settings → Environment Variables 画面で Name / Value を入力し、使用する環境を選択するだけ

本番用のキー、テスト用のキー、開発用のキーを分けたり、特定のブランチだけ特別な値を使いたい場合などに便利です。ぜひ活用してみてください。

参考リンク

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?