React Building and Deployment: From Development to Production

Last updated 2 months, 2 weeks ago | 123 views 75     5

Tags:- React

Introduction: Why Building and Deployment Matter in React

Creating an amazing React app is just half the journey. Building and deploying it correctly ensures users can actually access your application on the web.

Whether you’re deploying to GitHub Pages, Netlify, Vercel, or your own server, understanding the React build process is crucial for performance, SEO, and scalability.

Problem Solved: This guide helps React developers transform local projects into fully-deployed production apps.


Building a React App for Production

React apps are typically developed using Create React App (CRA), which bundles the app using Webpack, Babel, and other tools under the hood.

✅ Step 1: Create a React App

npx create-react-app my-app
cd my-app

✅ Step 2: Build the Project

npm run build

This generates a build/ folder containing minified, production-ready static assets:

/build
  ├── index.html
  ├── static/
      ├── js/
      └── css/

⚙️ CRA handles minification, bundling, hashing, and tree-shaking for optimal performance.


Deployment Options

There are several ways to deploy a React app. Let’s walk through popular methods:


1. GitHub Pages Deployment

Perfect for portfolios, demos, and small projects.

Install GitHub Pages Package

npm install gh-pages --save-dev

Update package.json

"homepage": "https://<your-username>.github.io/<repo-name>",
"scripts": {
  "predeploy": "npm run build",
  "deploy": "gh-pages -d build"
}

Deploy

npm run deploy

2. Deploy React to Netlify

✅ Connect GitHub Repository

  • Go to Netlify

  • Click "Add new site""Import from Git"

  • Select the GitHub repo

✅ Configure Build Settings

Setting Value
Build command npm run build
Publish dir build

✅ Done!

Netlify will auto-build and redeploy on each commit.


3. Deploy React to Vercel

  • Visit Vercel

  • Click "Import Project" and link your GitHub repo

  • Accept default build settings (CRA is auto-detected)

  • Click "Deploy"

✅ Vercel will auto-deploy on every push to main.


4. Manual Deployment via FTP or cPanel

  • Run npm run build

  • Upload contents of /build to your server's public_html or equivalent directory via FTP


Full Working Example (for GitHub Pages)

# Create app
npx create-react-app portfolio

# Add GitHub Pages
cd portfolio
npm install gh-pages --save-dev

# Update package.json
# (Add "homepage" and deploy scripts)

# Deploy
npm run deploy

Comparison Table: Deployment Platforms

Feature GitHub Pages Netlify Vercel
CI/CD Support
Custom Domains
Serverless Functions
Free SSL
Use Case Portfolios Blogs, SPAs Dynamic apps

Tips & Common Pitfalls

✅ Tips

  • Use a .env.production file to set environment-specific variables.

  • Run npm run lint before deployment to catch errors.

  • Add "homepage" in package.json to prevent broken paths in GitHub Pages.

❌ Common Pitfalls

Mistake Problem Solution
Skipping build step Site loads blank Always run npm run build before deploy
Wrong publish directory Netlify shows error Set to build/, not public/
No homepage in CRA Relative URLs break Set "homepage" in package.json
Misconfigured .env files Environment variables not loaded Use REACT_APP_ prefix

Conclusion: Ship Your React App with Confidence

Deploying a React application doesn’t need to be overwhelming. Whether you're going with GitHub Pages for simplicity or Netlify/Vercel for CI/CD power, the process is smooth once you understand the build pipeline.

Best Practices:

  • Always test your build/ locally before deploying

  • Use .env.production for secure configuration

  • Automate deployments with CI/CD tools