React Deployment

Please follow one of the following metbods.

Vitejs Deployment: Github Pages using the gh-pages CLI tool

Navigate into your project via a CLI tool (ubuntu/ terminal) Go through gitflow and save your current code.

git add
git commit -m 'commit-message'
git push 

Next, run the following command:

npm run build

You can check to see if your build worked by running the command:

npm run preview

You should be able to see your application within your browser at http://localhost:4173

After validating that this works, we will install the required packages: Run the command: npm install gh-pages --save-dev

Now we will setup the package.json: Add these scripts into scrips:

"predeploy": "npm run build",
"deploy": "gh-pages -d dist",

Now we will configure the vite.config.js: We need to add a key value pair for gh-pages:

The key will be base, the value should be ‘/name-of-your-repo’ The configure should look something like:

Now you should be able to run the command: npm run deploy

#==========================================================#

Vitejs Deployment: Github Pages through git push

Navigate into your project via a CLI tool (ubuntu/ terminal)

Go through gitflow and save your current code.

Run the following command:

git checkout -b gh-pages

Next, run the following command:

npm run build

You can check to see if your build worked by running the command:

npm run preview

You should be able to see your application within your browser at http://localhost:4173

Now we will configure the vite.config.js: We need to add a key value pair for deployment:

The key will be base, the value should be ‘/name-of-your-repo’ The configure should look something like:

Within your local machine we need to make a new github workflow within a yml file.

Create a new folder named .github Within the newly created directory create a workflows folder In the workflows folder create a new file named: jekyll-gh-pages.yml

Paste in this file:

In your GitHub, repo goto pages and then choose source as GitHub actions, not deploy from branch. Now you should be able to deploy when you push to this branch, before this will work we need to go through git flow (add commit and push) Then run the command:

git push origin gh-pages

Last updated