#previews in monorep
4 messages · Page 1 of 1 (latest)
Hi @tender hinge. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Based on the knowledge sources, here's how to configure preview deployments for your monorepo on Vercel:
Setup Steps
-
Generate a Preview Deploy Key
- Go to your Convex Dashboard project's Settings page
- Click "Generate Preview Deploy Key" to create a Preview deploy key
- Copy the generated key
-
Configure Vercel Environment Variable
- In Vercel, go to Environment Variables
- Create or edit the
CONVEX_DEPLOY_KEYvariable - Paste your preview deploy key
- Under "Environment", select only Preview (uncheck Production and Development)
-
Update Build Command
For a monorepo setup, you'll need to adjust the build command to navigate to your backend package. Based on the monorepo discussion, your build command should look something like:
cd packages/backend && npx convex deploy --cmd 'cd ../../packages/app && npm run build' --cmd-url-env-var-name NEXT_PUBLIC_CONVEX_URLThe
--cmd-url-env-var-nameflag is important for monorepos because Convex may not automatically detect the correct environment variable name to set. -
(Optional) Set up initial data
If you need to seed data for previews, add
--preview-run 'functionName'to the deploy command:cd packages/backend && npx convex deploy --cmd 'cd ../../packages/app && npm run build' --preview-run 'functionName' --cmd-url-env-var-name NEXT_PUBLIC_CONVEX_URL
How It Works
According to the Vercel preview deployments documentation:
npx convex deployreads the previewCONVEX_DEPLOY_KEYand creates a fresh Convex deployment for each Git branch- It sets the
CONVEX_URL(or your custom variable name) to point to the new preview deployment - Your app build reads this variable and connects to the preview backend
- Each preview has separate functions, data, and configuration from production