#previews in monorep

4 messages · Page 1 of 1 (latest)

tender hinge
#

I have a monorepo

packages/app -> app
packages/backend -> inside it os convex folder

how can I configure preview deploys (previews) on vercel?

limber boughBOT
#

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

  1. 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
  2. Configure Vercel Environment Variable

    • In Vercel, go to Environment Variables
    • Create or edit the CONVEX_DEPLOY_KEY variable
    • Paste your preview deploy key
    • Under "Environment", select only Preview (uncheck Production and Development)
  3. 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_URL
    

    The --cmd-url-env-var-name flag is important for monorepos because Convex may not automatically detect the correct environment variable name to set.

  4. (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 deploy reads the preview CONVEX_DEPLOY_KEY and 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

The knowledge sources indicate that Convex requires a Pro plan for preview deployments.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: