Introduction

Vite is a fast and modern frontend build tool that enhances the development experience. Vercel is a popular platform for deploying frontend applications, known for its ease of use and optimized performance. Deploying your Vite app to Vercel ensures quick deployments, automatic optimizations, and a smooth continuous integration/continuous deployment (CI/CD) process.


Key Features

  • Fast Build Times: Vite’s optimized build process ensures quick deployments.
  • Automatic SSL: Secure your application with HTTPS out of the box.
  • Custom Domains: Easily add and manage custom domains.
  • Serverless Functions: Integrate backend functionality seamlessly.
  • Global CDN: Deliver your app with low latency worldwide.
  • Easy Integration: Compatible with various frontend frameworks and tools.
  • Automatic Deployments: Vercel automatically creates and manages deployments for different branches.

Usage Instructions

  • Ensure vercel.json exist
{
  "rewrites": [{ "source": "/(.*)", "destination": "/" }]
}

This is absolutely need for vite to work in vercel as vite doesn’t have paths to route to, it only has the index route, but we internally reroute to the right path.

  • Vercel Account: Sign up for a Vercel account.
  • Git Repository: Your project should be in a Git repository (GitHub, GitLab, or Bitbucket).

Deployment Details

Automatic Deployments

Vercel streamlines the deployment process by automatically creating two types of deployments for your Vite app:

  1. Production Deployment (Main Deployment)

    • Branch: Typically linked to the main or master branch.
    • URL: Accessible via your custom domain or a default Vercel domain (e.g., your-app.vercel.app).
    • Purpose: Serves the live version of your application to end-users.
    • Automatic Build: Every commit pushed to the production branch triggers an automatic build and deployment, ensuring that your live site is always up-to-date.
  2. Preview Deployments (Development Deployments)

    • Branches: Any branch other than the production branch (e.g., feature branches, development branches).
    • URL: Each preview deployment gets a unique URL (e.g., feature-branch.your-app.vercel.app).
    • Purpose: Allows developers to test changes in an isolated environment before merging them into the production branch.
    • Automatic Build: Every commit pushed to any branch triggers a build specific to that branch, providing an instant preview of the changes.

Build Process

  • Detection: Vercel automatically detects your Vite project by identifying the presence of vite.config.js or related configuration files.
  • Build Command: Vercel uses the specified build command (usually vite build) to generate the dist folder containing the production-ready files.
  • Output Directory: The dist folder is used as the output directory for serving your application.

Continuous Integration/Continuous Deployment (CI/CD)

  • Build on Every Commit: Vercel integrates seamlessly with your Git repository, triggering a new build and deployment with every commit pushed to any branch.
  • Incremental Builds: Optimizes build times by only rebuilding what has changed, speeding up the deployment process.
  • Build Logs: Provides detailed logs for each build, helping you quickly identify and resolve any issues.

Environment Variables

  • Management: Securely manage environment variables through the Vercel dashboard.
  • Branch-Specific Variables: Set different environment variables for production and preview deployments, ensuring that sensitive data remains secure and configurations are appropriately managed for different environments.

Preview Deployments

  • Preview URLs: Automatically generated for each pull request, allowing you to test changes in a live environment before merging.
  • Collaboration: Share preview URLs with your team or stakeholders for feedback and testing.
  • Automatic Updates: Any new commits to the pull request branch will update the preview deployment in real-time.

Scalability

  • Automatic Scaling: Vercel automatically scales your application to handle traffic spikes without manual intervention.
  • Global CDN: Utilizes a global Content Delivery Network to ensure low latency and high availability for users worldwide.

Resources