Publish Projects with gh-pages

Publish Projects with gh-pages

first install gh-pages

npm i gh-pages --save-dev 

Second we should change all assets urls to something like:

process.env.PUBLIC_URL + "/test.jpg"; // the assets calling section

Add command to package.json to publish it

"scripts": {
    "deploy": "gh-pages -d build"
},

Build you react project using:

npm run build

At beginning of your package.json please add this command:

"homepage": "https://YOUR_GITHUB_USERNAME.github.io/GITHUB_REPO_NAME",

and then run

npm run deploy

If you face error called (fatal: A branch named ‘gh-pages’ already exists.) just delete “node_modules/.cache/gh-pages” then try again.

just remember that you should always run build then deploy it.

We are done here!

Leave a Reply

Required fields are marked *

Comments

  1. Was really helpful thanks

    Reply