React : deploy build and publish in gh
Create github public repository or push an existing repository from the command line
git remote add origin https://github.com/pradeepakv/reactApp.git
git branch -M master
git push -u origin master
Steps to deploy build and publish gh pages for any react projects:
Add in package.json: “homepage”: “https://accountName.github.io/repositoryName"
Open Git bash and execute following commands:
1. npm install gh-pages — save-dev
Skip below two steps if repository already exists
(else it will Reinitialize existing Git repository)
a.git init
b.git remote add origin https://accountName.github.io/repositoryName.git
2. Add in scripts:
“predeploy”: “npm run build”,
“deploy”: “gh-pages -d build”
3. npm run deploy
if any error, try npm run build
check for error in logs
now run: npm install -g npm@latest
Check your react-script dependency is available or not in package.json
If not available then add manually via:
npm install react-scripts — save
If any other package issues still:
Delete node_modules and package-lock.json
run npm install
run npm run start
Below steps 4. & 5. are not required if your repo is already updated
4. git add .
5. git commit -m “build and deploy”
Now in github, settings-> GitHub Pages ->generate url
change source to ghpages
You Are Done :) Happy to go….