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
- Installing the Netlify CLI:
npm install -g netlify-cli
- Deployment:
netlify deploy
- Configuration (netlify.toml):
[build]
command = "npm run build"
publish = "build"
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
Vercel
- Installing the Vercel CLI:
npm install -g vercel
- Deployment:
vercel
- 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