How to deploy a React app to production

· Category: React

How to deploy a React app to production

Building for Production

Run npm run build to create an optimized bundle with minified assets, hashed filenames, and dead code elimination. Serve the resulting build/ folder with a static host or a web server configured for single-page applications.

Environment Configuration

Use environment variables prefixed with REACT_APP_ (or VITE_ for Vite) to inject API endpoints and feature flags without hardcoding secrets:

REACT_APP_API_URL=https://api.example.com

Security Headers

Configure your server or CDN to send security headers. See how to implement Content Security Policy headers for guidance on preventing XSS and data injection attacks. HTTPS is mandatory; learn more in what is the difference between HTTP and HTTPS.

CI/CD

Automate builds, tests, and deployments. How to implement CI/CD with Jenkins covers pipeline construction, while how to use Docker multi-stage builds for smaller images helps containerize your React app efficiently.