dev-resources.site
for different kinds of informations.
How to Deploy a Vite + React App to GitHub Pages
Published at
12/13/2024
Categories
Author
Pedro Henrique Machado
Categories
1 categories in total
open
If you want to watch this in video form:
Deploying your React app built with Vite to GitHub Pages is quick and easy. Follow these steps:
Prerequisites
- A GitHub account.
- Node.js and npm installed.
- A React project created with Vite.
Steps
-
Install
gh-pages
From your project directory, run:
npm install --save-dev gh-pages
-
Update
package.json
Add ahomepage
field anddeploy
script:
{
"name": "my-vite-react-app",
"homepage": "https://<your-username>.github.io/<repo-name>/",
"scripts": {
"dev": "vite",
"build": "vite build",
"predeploy": "npm run build",
"deploy": "gh-pages -d dist"
}
}
Replace <your-username>
and <repo-name>
with your actual GitHub username and repository name.
-
Configure Vite Base URL
In
vite.config.js
, set thebase
to match your repo’s path:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
base: '/<repo-name>/', // Add this line
plugins: [react()]
})
- Build and Deploy Run:
npm run deploy
This command builds your app and pushes the dist
folder to the gh-pages
branch of your repo.
- Access Your Deployed Site Go to:
https://<your-username>.github.io/<repo-name>/
Done!
Your Vite React app is now live on GitHub Pages.
Articles
7 articles in total
Fetch Data With RTK Query: Crash Course
read article
React Router V7: A Crash Course
read article
JWT Authentication With NodeJS
read article
How to Deploy a Vite + React App to GitHub Pages
currently reading
React Redux Toolkit Course For Beginners - How To Build Using Redux
read article
FullStack App Using React and GraphQL (Apollo Client and Apollo Server)
read article
A Complete Guide to All React Hooks for Beginners
read article
Featured ones: