This guide covers deploying your React app to various platforms.
Before deploying, create a production build:
npm run buildThis creates a dist folder with optimized files.
-
Install Vercel CLI
npm install -g vercel
-
Login to Vercel
vercel login
-
Deploy
vercel
-
Deploy to Production
vercel --prod
-
Push to GitHub
git init git add . git commit -m "Initial commit" git branch -M main git remote add origin https://github.com/yourusername/your-repo.git git push -u origin main
-
Connect to Vercel
- Go to vercel.com
- Click "Add New Project"
- Import your GitHub repository
-
Configure Settings
- Framework Preset:
Vite - Build Command:
npm run build - Output Directory:
dist
- Framework Preset:
-
Add Environment Variables
- Go to Settings → Environment Variables
- Add:
VITE_API_BASE_URL= your production API URL
-
Deploy
- Click "Deploy"
-
Install Netlify CLI
npm install -g netlify-cli
-
Login
netlify login
-
Deploy
netlify deploy --prod --dir=dist
-
Connect to Netlify
- Go to netlify.com
- Click "Add new site" → "Import an existing project"
- Connect your GitHub repository
-
Configure
- Build command:
npm run build - Publish directory:
dist
- Build command:
-
Environment Variables
- Site settings → Environment Variables
- Add:
VITE_API_BASE_URL
npm run build# Using scp (replace with your server details)
scp -r dist/* user@your-server:/var/www/your-app/curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs# Install PM2
sudo npm install -g pm2
# Create ecosystem config
nano /home/user/your-project/ecosystem.config.jsmodule.exports = {
apps: [{
name: 'api-server',
script: 'npx',
args: 'json-server --watch db.json --port 3001',
cwd: '/home/user/your-project',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'production'
}
}]
};pm2 start ecosystem.config.js
pm2 save
pm2 startup # Follow the output instructionssudo nano /etc/nginx/sites-available/your-appserver {
listen 80;
server_name your-domain.com;
root /var/www/your-app;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}sudo ln -s /etc/nginx/sites-available/your-app /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginxAdd these in your dashboard:
| Variable | Value |
|---|---|
VITE_API_BASE_URL |
Your production API URL |
VITE_APP_NAME |
Your app name |
Create .env file in your project:
VITE_API_BASE_URL=http://localhost:3001
VITE_APP_NAME=My Bootcamp App- Build succeeds without errors
- App loads at production URL
- Login/logout works
- API calls work
- Environment variables set correctly
- Error handling works
- Loading states display correctly
- Check browser console for errors
- Verify
VITE_API_BASE_URLis correct - Ensure
baseinvite.config.jsmatches your deployment path
For SPA, ensure your server routes all requests to index.html.
Verify the API URL is accessible:
curl https://your-api-url.com/users