Introduction
Background Information
Starting and publishing a frontend project online requires the right tools, and React + Vite, hosted for free using GitHub Pages, is the perfect combination.
Vite is a modern build tool designed for speed and efficiency, making it an excellent choice for developing React applications. It provides instant server startup, fast hot module replacement (HMR), and optimized production builds.
React is a popular JavaScript library used to build interactive user interfaces, enabling developers to create reusable components for dynamic web applications.
GitHub Pages is a free and easy-to-use hosting service that allows developers to deploy static websites directly from a GitHub repository, making it ideal for portfolios, projects, and web experiments.
This guide will walk through the process of deploying a React + Vite web application to GitHub Pages.
Who is this Guide For?
This guide is for developers, students, and anyone looking to deploy a frontend app online. Whether you’re showcasing a portfolio project, sharing an interactive web app, or simply testing frontend designs, this step-by-step tutorial will help you set up, configure, and publish your project efficiently.
Context of Use
- For Developers: Useful for quick prototyping and sharing React applications.
- For Students: Helps in publishing academic or portfolio projects without the need for paid hosting.
- Common Challenges: Users may face issues related to incorrect configurations, missing dependencies, or incorrect repository setup.
Requirements
Before starting, ensure you have the following tools installed and configured on your system.
Hardware Requirements:
- A computer (Windows, macOS, or Linux)
- Stable internet connection
Software Requirements:
- Node.js (LTS version) – Required to run JavaScript applications.
- Download from: https://nodejs.org/en/download
- Git – Required for version control and pushing code to GitHub.
- Download from: https://git-scm.com/downloads
- GitHub Account – Needed to create a repository and host the project.
- Sign up at: https://github.com
- Code Editor (Recommended: VS Code) – To code and edit your project.
- Download from: https://code.visualstudio.com/Download/
Safety Considerations
- Be cautious when running commands in the terminal to avoid accidental file deletions.
- Ensure that you are working inside the correct directory before executing Git commands.
- Avoid committing sensitive data (e.g., API keys, credentials) to public repositories.
- Regularly update dependencies to prevent security vulnerabilities.
Step-by-Step Instructions
Step 1: Create a GitHub Repository
- Go to GitHub and log in.
- Click on New Repository.

- Enter a repository name (e.g., <your-repo-name>).
- Choose Public (or Private if you have GitHub Pro).
- Do not initialize with a README, .gitignore, or license (these will be added later).
- Click Create Repository.

Step 2: Set Up a React + Vite Project
- Open a terminal or command prompt.
-
Navigate to the directory where you want to create the project.
cd path/to/your/repo
-
Run the following command to create a new Vite project:
# Replace <your-project-name> with your desired project name npm create vite@latest <your-project-name> -- --template react-ts
-
Navigate into the project directory:
cd <your-project-name>
-
Install project dependencies:
npm install
Step 3: Configure Vite for GitHub Pages
- Open
vite.config.js
in a code editor. -
Add the following
base
property to the configuration:import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; export default defineConfig({ plugins: [react()], base: '/<your-repo-name>/', // Replace <your-repo-name> with your actual GitHub repository name });
Step 4: Modify package.json for Deployment
- Open
package.json
. -
Add this line to the top-level of the file:
"homepage": "https://<your-username>.github.io/<your-repo-name>/",
-
Add the following scripts inside the
scripts
section:"predeploy": "npm run build", "deploy": "gh-pages -d dist"
Below is an example of how your the
package.json
file should look after modification:{ "name": "my-vite-app", "private": true, "version": "0.0.0", "type": "module", "homepage": "https://anushnandyala.github.io/my-vite-app/", "scripts": { "dev": "vite", "build": "vite build", "lint": "eslint .", "preview": "vite preview", "predeploy": "npm run build", "deploy": "gh-pages -d dist" }, "dependencies": { "react": "^19.0.0", "react-dom": "^19.0.0" }, "devDependencies": { "@eslint/js": "^9.21.0", "@types/react": "^19.0.10", "@types/react-dom": "^19.0.4", "@vitejs/plugin-react": "^4.3.4", "eslint": "^9.21.0", "eslint-plugin-react-hooks": "^5.1.0", "eslint-plugin-react-refresh": "^0.4.19", "gh-pages": "^6.3.0", "globals": "^15.15.0", "vite": "^6.2.0" } }
-
Run the following command to install the GitHub Pages package:
npm install gh-pages --save-dev
Step 5: Initialize Git and Push the Project to GitHub
-
Initialize a Git repository:
git init
-
Add the remote GitHub repository:
git remote add origin https://github.com/<your-username>/<your-repo-name>.git
-
Commit and push the code:
git add . git commit -m "Initial commit" git branch -M main git push -u origin main
-
Go to
https://github.com/<your-username>/<your-repo-name>
to see your code on GitHub.

Step 6: Deploy the App to GitHub Pages
-
Run the deployment script:
npm run deploy
This builds the project and pushes the
dist/
folder to thegh-pages
branch.
Step 7: Enable GitHub Pages
- Navigate to your GitHub repository at
https://github.com/<your-username>/<your-repo-name>
.

- Go to Settings > Pages.

- Under Branch, select
gh-pages
and click Save.

-
Your site will be available at:
https://<your-username>.github.io/<your-repo-name>/

- When you make changes to your project, run
npm run deploy
to update the deployed site. Note that this is seperate from pushing changes to the main branch.
Step 8 (Optional): Automate Deployment with GitHub Actions
If you want to deploy to the website everytime you push to the main branch, you can set up a GitHub Action workflow using the following steps. Note that these following steps only work if authenticate to GitHub using a personal access token.
-
Inside your project, create a new folder.
mkdir -p .github/workflows
-
Create a new file inside that folder:
touch .github/workflows/deploy.yml
-
Open the
deploy.yml
file and add the following content:name: Deploy to GitHub Pages on: push: branches: - main # Runs when pushing to main permissions: contents: write # Ensure GitHub Actions can push to gh-pages jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout Repository uses: actions/checkout@v4 with: persist-credentials: false # Important for token-based authentication - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: 18 cache: 'npm' - name: Install Dependencies run: npm install - name: Build Project run: npm run build - name: Deploy to GitHub Pages env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: npm run deploy
-
Update the
deploy
script in thepackage.json
file to:"deploy": "gh-pages -d dist -u \"github-actions-bot <github-actions@github.com>\" --repo https://x-access-token:${GITHUB_TOKEN}@github.com/<your-username>/<your-repo-name>.git"
-
Commit and push the changes to main.
git add . git commit -m "Add GitHub Actions auto-deploy workflow" git push origin main
-
Go to the Actions tab in your GitHub repository to see the workflow running.

Now, every time you push to the main branch, Github Actions will:
- Install dependencies
- Build your Vite project
- Deploy the project to GitHub Pages using
gh-pages
Conclusion & Further Resources
You have successfully deployed a React + Vite app to GitHub Pages! If you encounter issues, here are some additional resources:
For accessibility and further assistance, check GitHub Discussions or Stack Overflow for troubleshooting common errors.
References
Node.js. (n.d.). Node.js Downloads. Retrieved March 10, 2025, from https://nodejs.org/
Git. (n.d.). Git - Downloads. Retrieved March 10, 2025, from https://git-scm.com/
GitHub Pages. (n.d.). GitHub Pages - Websites for you and your projects. Retrieved March 10, 2025, from https://pages.github.com/
Vite. (n.d.). Vite - Next generation frontend tooling. Retrieved March 10, 2025, from https://vitejs.dev/