Prerequisites
Before deploying to GitHub Pages, ensure you have:- A GitHub repository for your project
- GitHub Pages enabled in your repository settings
- Node.js 18+ and npm 9+ installed locally
- Write access to the repository
Configuration
Repository Settings
Yourpackage.json must include the homepage field pointing to your GitHub Pages URL:
package.json
Vite Base Path
Yourvite.config.js must include the base option matching your repository name:
vite.config.js
base path ensures that Vite generates correct asset URLs for the subdirectory where your app will be hosted.
Manual Deployment
Install gh-pages Package
Thegh-pages package is included as a dev dependency:
Deploy with npm Script
Build and Deploy
Run the deploy script which builds the project and publishes to GitHub Pages:This command:
- Runs
npm run buildto create the production build in thedistdirectory - Runs
gh-pages -d distto publish thedistfolder to thegh-pagesbranch
Wait for Deployment
GitHub Pages will automatically detect the new
gh-pages branch and deploy it. This typically takes 1-2 minutes.How gh-pages Works
Thegh-pages package:
- Creates or updates a
gh-pagesbranch in your repository - Copies the contents of the
distdirectory to this branch - Pushes the branch to GitHub
- GitHub Pages automatically serves the content from this branch
The
gh-pages branch is separate from your main branch and contains only the built static files, not your source code.Automated Deployment (CI/CD)
GitScope includes a GitHub Actions workflow that automatically deploys to GitHub Pages on every push to the main branch.Workflow Configuration
The workflow is defined in.github/workflows/deploy.yml:
.github/workflows/deploy.yml
Workflow Triggers
The workflow runs automatically when:- Code is pushed to the
mainbranch - Manually triggered using the “workflow_dispatch” event from the Actions tab
Required Permissions
The workflow requires specific permissions:contents: read- Read repository contentspages: write- Write to GitHub Pagesid-token: write- Write GitHub OIDC token for deployment
Setup GitHub Pages for Actions
Push to Main
Commit and push your changes to the
main branch. The workflow will trigger automatically.When using GitHub Actions deployment, you don’t need the
gh-pages package or branch. GitHub Pages will serve directly from the uploaded artifact.Troubleshooting
404 Errors After Deployment
If you see 404 errors for assets:- Verify the
basepath invite.config.jsmatches your repository name - Verify the
homepagefield inpackage.jsonis correct - Ensure both paths include a trailing slash:
/repo-name/
Deployment Not Updating
If changes aren’t reflected:- Clear your browser cache
- Wait 1-2 minutes for GitHub Pages to propagate changes
- Check the Actions tab for deployment errors
- Verify the build completed successfully
Permission Errors in GitHub Actions
If the workflow fails with permission errors:- Go to Settings → Actions → General
- Under “Workflow permissions”, select “Read and write permissions”
- Enable “Allow GitHub Actions to create and approve pull requests”
Next Steps
Build Process
Learn about the Vite build configuration and optimization
Environment Setup
Configure your development environment