In this tutorial, you will learn how to deploy your React application to production so it can be accessed by anyone on the web.
Introduction
After building a React app, the next step is to deploy it. Deployment makes your app publicly accessible. There are many hosting options including Vercel, Netlify, GitHub Pages, and traditional servers.
1. Build the Production Version
React provides a build command that optimizes your code for production:
npm run build
This creates a dist or build folder containing static files ready for deployment.
2. Deploy to Netlify
Netlify is a simple hosting platform for static sites:
- Sign up at Netlify.
- Click “New Site from Git” and connect your GitHub repository.
- Select the branch and set the build command to
npm run build. - Set the publish directory to
build(ordistif using Vite). - Click “Deploy Site”.
3. Deploy to Vercel
Vercel is another popular hosting platform for React apps:
- Sign up at Vercel.
- Import your GitHub repository.
- Vercel automatically detects it’s a React app and sets
npm run buildas the build command. - Click “Deploy”. Your app will be live with a generated URL.
4. Deploy to GitHub Pages
You can also host a React app on GitHub Pages:
npm install gh-pages --save-dev
Add the following to package.json:
"homepage": "https://yourusername.github.io/your-repo-name"
Add scripts:
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
Then run:
npm run deploy
5. Summary
In this tutorial, you learned how to deploy your React application using:
- Netlify
- Vercel
- GitHub Pages
Deployment makes your React app live and accessible to anyone. With this, you have completed the React Beginner series and are ready to build full-stack projects using React and Spring Boot.