In this example, a deployment of a regular CRA project is made to Vercel using Github secrets as env vars. Rather than using Vercel's auto-deployment feature to create a deployment for each commit to the main branch, this strategy uses GitHub Actions and Vercel CLI to deploy on whatever event that trigger a workflow.
- Create a vercel.json file at the root of your project folder to add Git configuration. Set
git.deploymentEnabled
to false which will prevent auto-deployments from commits.. - Then, let’s add the required values from Vercel as secrets in GitHub
- On your local computer or development environment, install the Vercel CLI and run
vercel login
- Inside your project folder, run
vercel link
to create a new Vercel project or link to an existing one - Navigate to the generated
.vercel
folder, and open project.json to find theprojectID
andorgId
- In GitHub, set
VERCEL_PROJECT_ID
to yourprojectID
andVERCEL_ORG_ID
to yourorgID
- Retrieve your Vercel Access Token and set it as the value of
VERCEL_TOKEN
- Define a Github Action to kick off a deployment based on one of these examples
As you can see in the deploy-static-pre-built-folder-and-create-pr-comment workflow, the application is pre built and then uploaded to Vercel.
To make this work properly, you need to change your project settings in Vercel.
- Go to you project page in Vercel
- Click in Settings
- On the left menu, make sure General is selected
- Go to Build & Development Settings section
- Choose
Other
forFramework Preset
- Leave Build Command field empty
- Hit
Save
button
This will prevent the build from being attempted and serve your content as-is.