0%
Deploying React Applications

Deployment

Going to production

10-15 min

Deploying React Applications

Deployment is the final step in developing a React application. We'll explore the different deployment options and the optimizations you need to make.

Preparing for deployment

Production build

npm run build

This command creates a build folder containing your application optimized for production.

Configuring environment variables

# .env.production
REACT_APP_API_URL=https://api.production.com
REACT_APP_ANALYTICS_ID=UA-XXXXXXXX-X

Popular deployment platforms

Netlify

  1. Installing the Netlify CLI:
npm install -g netlify-cli
  1. Deployment:
netlify deploy
  1. Configuration (netlify.toml):
[build]
  command = "npm run build"
  publish = "build"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

Vercel

  1. Installing the Vercel CLI:
npm install -g vercel
  1. Deployment:
vercel
  1. Configuration (vercel.json):
{
  "version": 2,
  "builds": [
    {
      "src": "package.json",
      "use": "@vercel/static-build",
      "config": { "distDir": "build" }
    }
  ]
}

Comments

Comments are powered by GitHub Discussions

Sign in with GitHub to join the discussion

Link copied!