How to Deploy React App

How to Deploy React App Deploying a React application is a critical step in bringing your frontend project from development to production. While building a responsive, interactive user interface with React is powerful, it’s only half the journey. A well-structured React app must be compiled, optimized, and hosted on a reliable server to be accessible to real users across the globe. Deploying a Rea

Nov 10, 2025 - 08:32
Nov 10, 2025 - 08:32
 1

How to Deploy React App

Deploying a React application is a critical step in bringing your frontend project from development to production. While building a responsive, interactive user interface with React is powerful, its only half the journey. A well-structured React app must be compiled, optimized, and hosted on a reliable server to be accessible to real users across the globe. Deploying a React app correctly ensures fast load times, improved user experience, search engine visibility, and scalability all essential for modern web applications.

Many developers, especially those new to React, assume that simply running npm run build is enough to deploy their app. However, deployment involves more than just generating static files. It requires understanding build output structure, choosing the right hosting platform, configuring server settings, setting up custom domains, enabling HTTPS, and optimizing performance through caching and compression. This guide provides a comprehensive, step-by-step walkthrough of how to deploy a React app effectively covering everything from basic methods to enterprise-grade strategies.

Whether youre deploying a personal portfolio, a startup MVP, or a large-scale SaaS product, mastering React deployment empowers you to ship high-performance applications with confidence. This tutorial will equip you with the knowledge to deploy your React app using multiple platforms, avoid common pitfalls, and follow industry best practices that ensure reliability, security, and speed.

Step-by-Step Guide

Step 1: Prepare Your React Project for Production

Before deployment, ensure your React application is ready for production. This begins with verifying your codebase is clean and optimized.

First, run npm run lint (if youre using ESLint) or yarn lint to catch syntax errors, unused variables, or inconsistent coding patterns. Address all warnings and errors. A clean codebase reduces the risk of runtime issues after deployment.

Next, test your application thoroughly in development mode. Use React Developer Tools in your browser to inspect components, check for memory leaks, and validate state management. Ensure all routes work correctly using React Router. Test forms, API calls, and responsive layouts across devices.

Now, optimize your build configuration. Open your package.json and confirm you have a build script:

"scripts": {

"build": "react-scripts build"

}

If youre using Vite, the script will be:

"scripts": {

"build": "vite build"

}

Run npm run build (or yarn build). This command generates a build folder (for Create React App) or a dist folder (for Vite), containing minified JavaScript, CSS, HTML, and static assets. The build process automatically:

  • Minifies JavaScript and CSS files
  • Hashes filenames for cache busting
  • Optimizes images
  • Creates a single HTML file with embedded script and style tags

Verify the build output by opening the index.html file inside the build folder in your browser. If the app renders correctly, youre ready for deployment.

Step 2: Choose a Deployment Platform

There are multiple platforms to deploy React apps, each with distinct advantages. The choice depends on your needs: budget, scalability, control, and team size.

Static Hosting Platforms are ideal for most React apps because React is a client-side framework. These platforms serve your built files as static assets, eliminating the need for server-side rendering infrastructure. Popular options include:

  • Netlify Offers free tier, automatic deployments from Git, custom domains, and built-in form handling.
  • Vercel Optimized for React and Next.js, with edge caching, preview deployments, and analytics.
  • GitHub Pages Free and simple, but limited to public repositories and lacks advanced features.
  • Cloudflare Pages Fast global CDN, free tier, and seamless Git integration.
  • Amazon S3 + CloudFront Enterprise-grade, highly customizable, but requires more configuration.
  • Render Supports static sites and Node.js backends, with automatic SSL and CI/CD.

For beginners, Netlify or Vercel are recommended due to their intuitive interfaces and generous free tiers. For teams needing advanced CI/CD pipelines or enterprise support, consider AWS, Azure, or Google Cloud.

Step 3: Deploy to Netlify

Netlify is one of the most popular choices for deploying React apps due to its simplicity and powerful features.

  1. Sign up for a free account at netlify.com.
  2. Connect your GitHub, GitLab, or Bitbucket account. Netlify will sync your repositories.
  3. Click New site from Git and select your React project repository.
  4. Under Build settings, set the build command to npm run build (or yarn build).
  5. Set the publish directory to build (for Create React App) or dist (for Vite).
  6. Click Deploy site. Netlify will automatically build your app and deploy it.

Within seconds, youll receive a unique Netlify URL (e.g., your-app-name.netlify.app). You can now share this link with anyone.

To use a custom domain, go to Domain settings and add your domain (e.g., www.yourwebsite.com). Netlify will guide you through DNS configuration typically requiring you to update CNAME records with your domain registrar.

Netlify also supports environment variables, form handling, serverless functions, and automatic SSL certificates all enabled by default.

Step 4: Deploy to Vercel

Vercel is optimized for React and Next.js applications. Its deployment process is nearly identical to Netlify.

  1. Create a free account at vercel.com.
  2. Click New Project and import your React repository from GitHub, GitLab, or Bitbucket.
  3. Vercel auto-detects React projects. Confirm the build command is npm run build and the output directory is build.
  4. Click Deploy. Vercel builds your app and provides a preview URL (e.g., your-app.vercel.app).

Vercel automatically enables:

  • HTTPS via Lets Encrypt
  • Edge Network caching for faster global delivery
  • Preview deployments for every pull request
  • Analytics dashboard showing visitor metrics

To use a custom domain, navigate to Settings > Domains and add your domain. Vercel will generate DNS records to copy into your registrars dashboard.

Step 5: Deploy to GitHub Pages

GitHub Pages is a free option if youre comfortable with public repositories and dont need advanced features.

  1. Ensure your React app is built: npm run build.
  2. In your repository, go to Settings > Pages.
  3. Under Source, select Deploy from a branch and choose main (or master) and the /build folder.
  4. Click Save. GitHub Pages will build and deploy your app.
  5. Wait a few minutes, then visit your site at https://username.github.io/repository-name.

Important: GitHub Pages only supports static files. If your app uses client-side routing (React Router), you must create a 404.html file in the build folder that mirrors your index.html. This ensures deep links work correctly. You can automate this with a script in your package.json:

"scripts": {

"prebuild": "cp build/index.html build/404.html",

"build": "react-scripts build"

}

GitHub Pages does not support custom server configurations or environment variables, making it less suitable for complex applications.

Step 6: Deploy to Amazon S3 and CloudFront

For organizations requiring maximum control, scalability, and performance, deploying to AWS S3 and CloudFront is a robust solution.

  1. Create an S3 bucket via the AWS Console. Enable Static website hosting in the bucket properties.
  2. Set the index document to index.html and error document to index.html (to handle client-side routing).
  3. Upload all files from your build folder to the bucket.
  4. Configure bucket policy to allow public read access:
{

"Version": "2012-10-17",

"Statement": [

{

"Sid": "PublicReadGetObject",

"Effect": "Allow",

"Principal": "*",

"Action": "s3:GetObject",

"Resource": "arn:aws:s3:::your-bucket-name/*"

}

]

}

  1. Create a CloudFront distribution. Set the origin domain to your S3 bucket endpoint.
  2. In Origin Request Policy, select CORS-S3Origin to handle cross-origin requests.
  3. Enable Viewer Protocol Policy to redirect HTTP to HTTPS.
  4. Set Default Root Object to index.html.
  5. Deploy the distribution. Wait 510 minutes for propagation.

Finally, point your domains DNS records to the CloudFront distributions domain name using a CNAME record. AWS provides automatic SSL certificates via ACM if you use a custom domain.

This method offers global CDN caching, DDoS protection, and fine-grained access control ideal for high-traffic applications.

Step 7: Configure Client-Side Routing for Production

One of the most common deployment issues with React apps is broken routing. If youre using React Router (v5 or v6), navigating directly to a route like /about or /products/123 may return a 404 error in production.

This happens because the server receives the request for /about and looks for a file named about which doesnt exist. The solution is to configure your hosting platform to serve index.html for all routes.

  • Netlify: Create a _redirects file in the build folder with: /* /index.html 200.
  • Vercel: Add a vercel.json file in the root with:
    {
    

    "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]

    }

  • GitHub Pages: Use the 404.html workaround mentioned earlier.
  • CloudFront: Set the error response to return index.html for 404 errors.
  • Apache: Add RewriteEngine On and RewriteCond %{REQUEST_FILENAME} !-f rules to .htaccess.
  • Nginx: Add try_files $uri $uri/ /index.html; to your server block.

Always test deep links after deployment. Visit yourdomain.com/about directly in an incognito window to confirm it loads correctly.

Step 8: Enable HTTPS and SSL

Modern browsers require HTTPS for features like service workers, geolocation, and secure cookies. All major hosting platforms (Netlify, Vercel, Cloudflare, GitHub Pages) provide free SSL certificates automatically.

If youre self-hosting (e.g., on a VPS with Nginx), use Lets Encrypt with Certbot:

sudo apt install certbot python3-certbot-nginx

sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

Certbot will automatically configure your Nginx server to use HTTPS and set up automatic renewal.

Verify your SSL setup using SSL Labs SSL Test. Aim for an A+ rating.

Step 9: Test Your Deployed App

After deployment, conduct a final quality assurance check:

  • Test all routes manually (home, about, contact, product pages).
  • Check forms, API calls, and authentication flows.
  • Verify images and fonts load correctly.
  • Test on mobile and tablet devices using browser dev tools.
  • Use Lighthouse in Chrome DevTools to audit performance, accessibility, and SEO.
  • Check for mixed content warnings (HTTP resources on HTTPS site).
  • Confirm that environment variables (e.g., API keys) are not exposed in client-side code.

Use tools like Google PageSpeed Insights and GTmetrix to analyze load times and identify optimization opportunities.

Best Practices

Optimize Your Build for Performance

Reacts default build process is already optimized, but you can go further:

  • Code Splitting: Use React.lazy() and Suspense to load components only when needed. This reduces initial bundle size.
  • Image Optimization: Use modern formats like WebP and AVIF. Tools like sharp or next/image (if using Next.js) can automate this.
  • Remove Unused Dependencies: Run npm ls or yarn list to identify unused packages. Remove them with npm uninstall.
  • Tree Shaking: Ensure your bundler (Webpack or Vite) removes unused code. Use ES6 imports (import { func } from 'module') instead of CommonJS (require()) for better tree shaking.
  • Preload Critical Resources: Add <link rel="preload"> for key fonts or scripts in your public/index.html.

Use Environment Variables Securely

Never hardcode API keys, database credentials, or secrets in your React code. Use environment variables instead.

Create a .env file in your project root:

REACT_APP_API_URL=https://api.yourdomain.com

REACT_APP_GOOGLE_MAPS_KEY=your-key-here

Access them in code with process.env.REACT_APP_API_URL.

Important: Only variables prefixed with REACT_APP_ are exposed to the client in Create React App. Avoid exposing sensitive data like AWS secrets or private keys these should reside on your backend server.

Implement Caching Strategies

Proper caching reduces server load and improves user experience:

  • Set long cache headers for static assets (JS, CSS, images) e.g., 1 year.
  • Use cache-busting filenames (React does this automatically with hashes).
  • Configure service workers for offline support using workbox or react-app-rewired.
  • Use CDN caching (CloudFront, Cloudflare) to serve content from edge locations.

Monitor and Log Errors

Production apps need error tracking. Integrate tools like:

  • Sentry Captures JavaScript errors and performance issues.
  • LogRocket Records user sessions and replays bugs.
  • Google Analytics Tracks user behavior and page views.

Install Sentry via npm:

npm install @sentry/react @sentry/tracing

Then initialize it in your index.js:

import * as Sentry from "@sentry/react";

import { Integrations } from "@sentry/tracing";

Sentry.init({

dsn: "your-dsn-here",

integrations: [new Integrations.BrowserTracing()],

tracesSampleRate: 1.0,

});

This helps you detect and fix issues users encounter without you being present.

Ensure Accessibility and SEO

Deployed React apps must be accessible and SEO-friendly:

  • Use semantic HTML (<header>, <nav>, <main>).
  • Add descriptive <title> and <meta name="description"> tags in public/index.html.
  • Use React Helmet or Next.js Head component to dynamically update metadata per route.
  • Add alt attributes to all images.
  • Ensure keyboard navigation and ARIA labels are implemented.

Set Up Continuous Deployment (CI/CD)

Automate deployments to reduce human error and speed up releases:

  • Connect your GitHub repository to Netlify or Vercel changes to the main branch auto-deploy.
  • Use GitHub Actions to build and deploy to S3 or a custom server.
  • Run tests before deployment: npm test and npm run build in your workflow.

Example GitHub Actions workflow (.github/workflows/deploy.yml):

name: Deploy React App

on:

push:

branches: [ main ]

jobs:

deploy:

runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v3

- uses: actions/setup-node@v3

with:

node-version: '18'

- run: npm ci

- run: npm run build

- uses: peaceiris/actions-gh-pages@v3

with:

github_token: ${{ secrets.GITHUB_TOKEN }}

publish_dir: ./build

publish_branch: gh-pages

This workflow deploys your app to GitHub Pages on every push to main.

Tools and Resources

Core Tools

  • React The JavaScript library for building user interfaces. react.dev
  • Create React App (CRA) Official toolchain for bootstrapping React apps. create-react-app.dev
  • Vite Next-generation frontend tooling with instant server start and hot module replacement. vitejs.dev
  • React Router Declarative routing for React apps. reactrouter.com
  • ESLint JavaScript/TypeScript linter for code quality. eslint.org
  • Prettier Code formatter for consistent style. prettier.io

Deployment Platforms

Performance and Monitoring

Learning Resources

Real Examples

Example 1: Personal Portfolio on Netlify

A developer builds a React portfolio with React Router for pages like About, Projects, and Contact. They use Netlify for deployment:

  • Repository: github.com/username/portfolio
  • Build command: npm run build
  • Publish directory: build
  • Custom domain: www.johndoe.dev
  • Added _redirects file with /* /index.html 200 to handle routing.
  • Integrated Google Analytics and Sentry for error tracking.
  • Result: Site loads in under 1.2 seconds on mobile, passes Lighthouse audit with 98/100 score.

Example 2: E-Commerce UI on Vercel

A startup deploys a React-based product catalog using Vercel:

  • Uses Vite for faster builds and hot reload.
  • Implements code splitting for product category pages.
  • Uses environment variables for API endpoints.
  • Enables preview deployments for every pull request marketing team can review changes before merge.
  • Uses Vercel Analytics to track user behavior and optimize high-traffic pages.
  • Result: 40% faster load times compared to previous Angular app; 30% increase in conversion rate.

Example 3: Enterprise App on AWS S3 + CloudFront

A financial services company deploys a React dashboard with strict security requirements:

  • Hosted on S3 with CloudFront distribution across 15 global edge locations.
  • Uses AWS WAF to block malicious traffic.
  • Implements strict CORS policies and token-based authentication via backend API.
  • Uses CloudFront Functions to modify headers for security headers (CSP, X-Frame-Options).
  • Automated CI/CD via GitHub Actions and AWS CodePipeline.
  • Result: 99.99% uptime, sub-200ms latency globally, compliant with SOC2 and GDPR.

Example 4: Open Source Project on GitHub Pages

An open-source React component library is deployed on GitHub Pages:

  • Build script includes cp build/index.html build/404.html.
  • Uses a custom domain via CNAME record.
  • Automated deployment via GitHub Actions on every git tag.
  • Result: 15,000+ monthly visitors; documentation and demos accessible worldwide without cost.

FAQs

Can I deploy a React app for free?

Yes. Netlify, Vercel, GitHub Pages, and Cloudflare Pages offer free tiers suitable for personal projects, portfolios, and small applications. These platforms provide SSL, custom domains, and global CDN caching at no cost.

Why does my React app show a blank page after deployment?

This usually occurs due to incorrect build output paths, missing environment variables, or unhandled routing. Check your browsers console for errors. Ensure the build directory is correctly set in your hosting platform, and confirm your index.html is being served. Also, verify that API endpoints are accessible from the deployed domain.

Do I need a backend to deploy a React app?

No. React apps are static and can be deployed without a backend. However, if your app interacts with a database, authenticates users, or processes payments, youll need a separate backend service (e.g., Node.js, Firebase, Supabase) hosted elsewhere.

How do I update my deployed React app?

Push new code to your Git repository. If youre using Netlify, Vercel, or GitHub Pages with CI/CD, the site auto-deploys. Otherwise, rebuild locally with npm run build and re-upload the build folder to your hosting platform.

Whats the difference between React and Next.js deployment?

React apps are static and deployed as HTML, CSS, and JS files. Next.js supports server-side rendering (SSR) and static site generation (SSG), requiring Node.js environments or serverless functions. Next.js apps can be deployed on Vercel (optimized) or any Node.js server, while React apps can be hosted on any static server.

How do I handle API keys in React?

Never expose API keys in client-side code. Use environment variables prefixed with REACT_APP_ only for non-sensitive keys. For sensitive keys (e.g., Stripe, AWS), make API calls from a backend server and proxy requests from React.

How long does it take to deploy a React app?

With automated platforms like Netlify or Vercel, deployment takes 30 seconds to 2 minutes. Manual uploads to S3 or FTP may take 515 minutes depending on file size and internet speed.

Can I deploy a React app on shared hosting?

Yes. Upload the contents of the build folder to your hosting providers public directory (e.g., public_html). Configure your server to serve index.html for all routes (via .htaccess or server config). Most shared hosts support this.

What should I do if my app breaks after a deploy?

Use version control to revert to the previous commit. Most platforms (Netlify, Vercel) maintain deployment history and allow one-click rollbacks. Always test in staging before deploying to production.

Conclusion

Deploying a React app is no longer a complex, intimidating task. With modern tools and platforms, anyone can go from a local development environment to a globally accessible, high-performance web application in minutes. Whether you choose Netlify for simplicity, Vercel for speed, or AWS S3 for control, the key is understanding your build output, configuring routing correctly, enabling HTTPS, and optimizing for performance and accessibility.

The practices outlined in this guide from using environment variables securely to implementing caching and error monitoring form the foundation of professional React deployment. These arent just technical steps; theyre essential habits that separate amateur projects from production-ready applications.

As you deploy more apps, youll develop an intuition for what works best for your use case. Start with a free platform, automate your workflow, monitor performance, and iterate. Remember: deployment isnt a one-time event its an ongoing process of refinement, testing, and improvement.

By mastering how to deploy React apps, youre not just publishing code youre delivering experiences. And in todays digital landscape, thats what truly matters.