Skip to main content

Overview

After building your portfolio, you can deploy it to various hosting platforms. This guide covers the most popular options for hosting static React applications.

Environment Variables

Your portfolio uses EmailJS for the contact form, which requires three environment variables:
.env
VITE_SEVICE_ID=your_emailjs_service_id
VITE_TEMPLATE_ID=your_emailjs_template_id
VITE_PUBLIC_KEY=your_emailjs_public_key
In Vite, environment variables must be prefixed with VITE_ to be exposed to your application. This is a security feature to prevent accidentally exposing server-side secrets.

Getting EmailJS Credentials

1

Create an EmailJS account

Sign up at emailjs.com if you haven’t already.
2

Get your Public Key

Navigate to Account → API Keys to find your Public Key (VITE_PUBLIC_KEY).
3

Create an Email Service

Go to Email Services → Add New Service. Connect your email provider and note the Service ID (VITE_SEVICE_ID).
4

Create an Email Template

Go to Email Templates → Create New Template. Customize your template and note the Template ID (VITE_TEMPLATE_ID).

Deployment Platforms

Deploy to Vercel

Vercel offers the simplest deployment experience with automatic deployments from Git.
1

Install Vercel CLI (Optional)

npm install -g vercel
2

Deploy via CLI

From your project root:
vercel
Follow the prompts to link your project.
3

Or Deploy via Git Integration

  1. Push your code to GitHub, GitLab, or Bitbucket
  2. Go to vercel.com and sign in
  3. Click “Add New Project”
  4. Import your repository
  5. Vercel auto-detects Vite configuration
  6. Click “Deploy”
4

Configure Environment Variables

In your Vercel project dashboard:
  1. Go to Settings → Environment Variables
  2. Add each variable:
    • VITE_SEVICE_ID
    • VITE_TEMPLATE_ID
    • VITE_PUBLIC_KEY
  3. Select all environments (Production, Preview, Development)
  4. Save and redeploy

Vercel Configuration (Optional)

Create vercel.json for custom configuration:
vercel.json
{
  "buildCommand": "npm run build",
  "outputDirectory": "dist",
  "framework": "vite"
}
Vercel provides automatic HTTPS, CDN distribution, and instant rollbacks. Each Git push creates a preview deployment.

Custom Domain Setup

All platforms support custom domains:
1

Purchase a domain

Buy a domain from providers like Namecheap, Google Domains, or Cloudflare.
2

Configure DNS

Add DNS records pointing to your hosting platform:For Vercel/Netlify/Cloudflare:
  • Add CNAME record: wwwyour-site.platform.com
  • Add A record for apex domain (provided by platform)
3

Add domain in platform settings

  • Vercel: Settings → Domains
  • Netlify: Site settings → Domain management
  • GitHub Pages: Settings → Pages → Custom domain
  • Cloudflare Pages: Custom domains → Set up a custom domain
4

Wait for DNS propagation

DNS changes can take 24-48 hours to propagate globally.

Common Deployment Issues

Issue: Blank Page After Deployment

Possible Causes:
  • Incorrect base configuration in vite.config.js
  • JavaScript errors (check browser console)
  • Missing environment variables
Solution:
vite.config.js
// For root domain deployment
export default defineConfig({
  base: '/',
})

// For subdirectory deployment
export default defineConfig({
  base: '/subdirectory/',
})

Issue: 404 on Page Refresh

Problem: Refreshing any route except home shows 404 Solution: Configure your hosting platform to redirect all routes to index.html:
[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

Issue: Environment Variables Not Working

Checklist:
  • Variables are prefixed with VITE_
  • Variables are set in hosting platform dashboard
  • Redeployed after adding variables
  • Using import.meta.env.VITE_VAR_NAME (not process.env)

Issue: Contact Form Not Working

Common Problems:
  1. CORS errors: Verify EmailJS domain is whitelisted
  2. Invalid credentials: Double-check Service ID, Template ID, and Public Key
  3. Missing environment variables: Ensure all three variables are set correctly
Testing:
// Add console logs in Contact.jsx to debug
console.log('Service ID:', import.meta.env.VITE_SEVICE_ID);
console.log('Template ID:', import.meta.env.VITE_TEMPLATE_ID);
console.log('Public Key:', import.meta.env.VITE_PUBLIC_KEY);
Remove debug console logs before production deployment to avoid exposing sensitive data in browser console.

Performance Optimization

Enable Compression

Most platforms enable gzip/brotli compression automatically. Verify in browser DevTools:
  • Check Content-Encoding header in Network tab
  • Should show gzip or br

Configure Caching

Vite automatically adds content hashes to filenames for cache busting:
assets/index-a1b2c3d4.js
assets/index-e5f6g7h8.css
This allows aggressive caching of assets while ensuring updates are always fetched.

Optimize Images

Before deployment:
  1. Compress images using tools like TinyPNG or Squoosh
  2. Use modern formats (WebP, AVIF) with fallbacks
  3. Implement lazy loading for below-the-fold images

Monitoring and Analytics

Add Analytics

Google Analytics:
// Add to index.html
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'GA_MEASUREMENT_ID');
</script>
Vercel Analytics:
npm install @vercel/analytics
App.jsx
import { Analytics } from '@vercel/analytics/react';

function App() {
  return (
    <>
      {/* Your app */}
      <Analytics />
    </>
  );
}

Error Tracking

Consider integrating error tracking services:
  • Sentry: Comprehensive error tracking
  • LogRocket: Session replay and monitoring
  • Rollbar: Real-time error monitoring

Deployment Checklist

Before going live:
  • Production build completes without errors
  • All environment variables configured on hosting platform
  • Contact form tested and working
  • All routes accessible and no 404 errors
  • Custom domain configured (if applicable)
  • HTTPS enabled
  • Responsive design tested on mobile/tablet/desktop
  • Browser compatibility tested (Chrome, Firefox, Safari)
  • Lighthouse score reviewed (aim for 90+ on Performance)
  • Meta tags and SEO optimized
  • Analytics tracking configured
  • Favicon and app icons present

Continuous Deployment

All recommended platforms support automatic deployments:
  1. Push to Git: Commit and push changes to your repository
  2. Automatic Build: Platform detects changes and triggers build
  3. Deploy: New version goes live automatically
  4. Rollback: Instantly revert to previous deployment if needed
Set up branch-based deployments: production branch for live site, staging branch for testing.

Next Steps

Build Configuration

Learn about build optimization and configuration

Customization Guide

Customize your portfolio’s design and content

Build docs developers (and LLMs) love