Deploy your React applications using GitHub-Pages
Table Of Contents:
Step 2: Install gh-pages and add deploy to scripts in package.json
Step 4: For a project page, ensure your project’s settings use gh-pages
So, You have built a React app.
Next step? Deploying.
How you gonna do it?? Just follow along!!
Step 1: Add homepage to package.json
This is a very important step. DONT skip it.
"homepage": "https://myusername.github.io/my-app"
"homepage": "https://myusername.github.io"
"homepage": "https://mywebsite.com"
Create React App uses the homepage field to determine the root URL in the built HTML file.
Step 2: Install gh-pages and add deploy to scripts in package.json
npm install --save gh-pages
yarn add gh-pages
+ "predeploy": "npm run build",
+ "deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build"
The predeploy script will run automatically before deploy is run.
Modify your package.json scripts to push deployments to master:
"predeploy": "npm run build",
- "deploy": "gh-pages -d build",
+ "deploy": "gh-pages -b master -d build"
Step 3: Deploy the site by running npm run deploy
npm run deploy
Step 4: For a project page, ensure your project’s settings use gh-pages
And tadaa! 🎉 You have published your application successfully.
It might take some time to actually be available but you have done your part.🌟
Give yourself a high five!!1