Your app works locally. Now let's get it live. This lesson covers environment variables, the production build process, deploying to Netlify and Vercel, and setting up automatic deployments from GitHub.
During development, Vite serves your source files directly. For production, it bundles and minifies everything into optimized static files. Run the build command and inspect what it produces.
npm run build
# Output:
# dist/
# index.html
# assets/
# index-abc123.js ← all your JavaScript, minified
# index-def456.css ← all your CSS
# Preview the production build locally before deploying
npm run preview
The dist/ folder is what you deploy. It's just static files — no server needed. That's what makes Vue apps cheap and fast to host.
Never hardcode API keys or environment-specific URLs in your code. Use Vite's environment variable system.
# Vite only exposes vars that start with VITE_
VITE_API_URL=http://localhost:3000
VITE_APP_TITLE=My App Dev
VITE_API_URL=https://api.myapp.com
VITE_APP_TITLE=My App
// Access with import.meta.env
const apiUrl = import.meta.env.VITE_API_URL
const isDev = import.meta.env.DEV
const isProd = import.meta.env.PROD
// Use in API calls
const res = await fetch(`${import.meta.env.VITE_API_URL}/users`)
.env.local to your .gitignore. This file holds your real secrets and never gets committed. The .env file (with non-secret defaults) can be committed safely.[build]
command = "npm run build"
publish = "dist"
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
# This redirect is REQUIRED for Vue Router history mode
# Without it, refreshing on /about returns a 404
Push your code to GitHub, then connect the repo in Netlify. Set your environment variables in Netlify's dashboard (Site Settings → Environment Variables). Netlify auto-deploys every time you push to main.
npm i -g vercel
vercel login
vercel # follow the prompts
# Or connect GitHub repo at vercel.com for auto-deploys
{
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}
name: Deploy to Netlify
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run build
- uses: netlify/actions/cli@master
with:
args: deploy --dir=dist --prod
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
npm run build and inspect the dist/ folder.npm run preview and verify everything works on the production build.npm run build creates an optimized dist/ folder of static files.VITE_ prefix for environment variables. Access them via import.meta.env.