Web DevFebruary 13, 2025•8 min read
Deploy Vite to GitHub Pages
A step-by-step guide to deploying your Vite project to GitHub Pages using GitHub Actions for automatic deployment on every push.
Configure Vite for GitHub Pages#
The key is setting the correct base path in your Vite config. GitHub Pages serves your site from https://<username>.github.io/<repository-name>/, so your assets need to be prefixed accordingly.
Create a GitHub Repository and Push Your Code#
If you haven't already, set up your repository and push your code:
- Create a new repository on GitHub
- Initialize Git in your local project folder (
git init) - Add the GitHub repository as a remote (
git remote add origin <your-repo-url>) - Stage, commit, and push your initial project code (including the updated
vite.config.js) to themain(ormaster) branch
Set Up GitHub Actions for Automatic Deployment#
This method automatically builds and deploys your site whenever you push changes to your main branch.
Create the Workflow#
- Create the workflow directory: In your project root, create a folder path
.github/workflows/ - Create a workflow file: Inside
.github/workflows/, create a new file nameddeploy.yml(or any other.ymlname) - Paste the following workflow configuration into
deploy.yml:
Commit and Push the Workflow File#
Configure GitHub Pages Settings#
- Go to your GitHub repository on the web
- Click on the "Settings" tab
- In the left sidebar, click on "Pages"
- Under "Build and deployment":
- For "Source", select "GitHub Actions" (This option should appear automatically once your workflow runs successfully for the first time after pushing the
.ymlfile)
- For "Source", select "GitHub Actions" (This option should appear automatically once your workflow runs successfully for the first time after pushing the
Verify Deployment#
- Go to the "Actions" tab in your GitHub repository — you should see the workflow running (or completed) after you pushed the
deploy.ymlfile or pushed new code tomain - Once the workflow completes successfully, go back to Settings → Pages
- GitHub Pages will display the URL where your site is published (e.g.,
https://<username>.github.io/<repository-name>/) - It might take a minute or two for the site to become live after the first deployment
Summary#
With this setup, every push to main will automatically build your Vite project and deploy it to GitHub Pages. No manual build steps required — just push and your site updates.