Not a front-end developer, but I keep shipping anyway.
This is my personal portfolio built with Vite, React, and TypeScript. It’s fast, lightweight, and deployed using GitHub Actions to GitHub Pages.
To deploy your Vite project to GitHub Pages, follow these steps:
NOTE:: Create a .env file in your root directory and fill is as .env.example from EmailJS to setup working contact form which sends message directly to your mail.
Run the build command to generate the static files:
npm run buildThis will create a dist/ directory containing your production-ready app.
Update your vite.config.js to set the correct base path for GitHub Pages:
import { defineConfig } from 'vite'
export default defineConfig({
base: '/your-repo-name/', // replace with your GitHub repo name
})This ensures the correct asset paths when served from GitHub Pages.
If you're using react-router, make sure to specify the basename in your router configuration:
<BrowserRouter basename="your-repo-name">Replace your-repo-name with your actual repository name.
Create a workflow file to automate the deployment:
Path: .github/workflows/deploy.yml
name: Deploy
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install
- run: npm run build
- uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./distThis workflow will:
- Build your app
- Deploy the
dist/folder to GitHub Pages on every push tomain
Go to your repository's:
Settings → Pages
- Set the source to GitHub Actions (or to the
gh-pagesbranch if created by the workflow).
Once deployed, your site will be available at:
https://{your-username}.github.io/{your-repo-name}/
Make sure to replace {your-username} and {your-repo-name} accordingly.
npm install
npm run devThis runs the app locally at http://localhost:5173 by default.
- Make sure the
basepath invite.config.jsmatches your repo name exactly. - This setup uses GitHub Actions for automated deployment. No need to manually run deploy scripts.
- For custom domains, add a
CNAMEfile to thepublic/directory.