Nearby lessons

44 of 44

🚀 ReactJS – Deployment

📌 What is React Deployment?

How to Deploy a React Application?

After building a React app, you need to deploy it so users can access it in a browser. Deployment means hosting your production-ready build on a server or a platform.

React provides a build folder with optimized static files that can be deployed to services like Netlify, Vercel, GitHub Pages, or traditional web servers.

📦 Creating a Production Build

  • Run npm run build to create a production build
  • This generates an optimized build/ folder
  • The build contains minified JavaScript, CSS, and HTML files
  • These files are static and can be served by any web server

🌐 Deploying to Netlify

Netlify is a popular platform for hosting React apps.

  1. Install Netlify CLI (optional): npm install netlify-cli -g
  2. Run npm run build
  3. Drag and drop the build/ folder into Netlify dashboard
  4. Or use netlify deploy command

⚡ Deploying to Vercel

Vercel is another popular option.

  1. Install Vercel CLI: npm install -g vercel
  2. Run vercel in the project folder
  3. Follow the instructions and your app will be live

📁 Deploying to GitHub Pages

GitHub Pages can host React apps for free.

  1. Install package: npm install gh-pages --save-dev
  2. Add "homepage": "https://username.github.io/repo-name" in package.json
  3. Add scripts:
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build"
  4. Run npm run deploy

🖥️ Deploying on Traditional Web Server

You can also deploy the build/ folder to Apache, Nginx, or any hosting provider.

Just copy the build/ folder contents into your server's public_html or www directory.

🧠 Test Your Knowledge

4 Questions

Progress: 0 / 4
Keep Going!Course Complete!