Q1. How do you build a React app for production?
Run npm run build (or yarn build) in a CRA project. This creates an optimized production build in the build folder, with minified files and hashed filenames for caching.
Q2. What is included in the build process?
The build process includes minification, bundling, tree shaking, and environment variable replacement. It also optimizes images and generates source maps optionally.
Q3. How do you set environment variables for different builds?
In CRA, you can use .env files. Variables with REACT_APP_ prefix are embedded during build. You can have .env.production, .env.development, etc.
Q4. What is the purpose of the build folder?
The build folder contains static files ready to be served by a web server. You can deploy its contents to any hosting service like Netlify, Vercel, or AWS S3.
Q5. How do you test the production build locally?
You can use a static server like serve: npx serve build. This serves the build folder locally to verify everything works before deployment.
