vite-on-github
v1.0.0
Published
One command to prepare any Vite project for GitHub Pages — auto config, base paths, CI, and router setup
Maintainers
Readme
vite-on-github

One command to prepare any Vite project for GitHub Pages — auto config, base paths, CI, and router setup.
No more fighting with base paths, broken assets, or manual GitHub Actions YAML.
Live demo: foisalislambd.github.io/vite-on-github (built from /demo)
The Problem
Deploying a Vite app to GitHub Pages usually means:
- Setting the correct
baseURL (/repo-name/vs/) - Fixing broken asset paths when the app lives in a subfolder
- Configuring React Router / Vue Router
basename - Writing a GitHub Actions workflow from scratch
- Adding SPA fallback (
404.html) for client-side routing
That's a lot of steps — and easy to get wrong.
The Solution
Run one command inside your Vite project:
npx vite-on-githubIt automatically:
- Installs
vite-basepath— relative asset paths that work in any subfolder - Patches your
vite.config.ts/vite.config.jsto add the plugin - Updates React Router / Vue Router with
getBase()when detected - Creates
.github/workflows/deploy.ymlfor GitHub Pages - Adds SPA
404.htmlfallback in the CI build step
Your app works at:
https://username.github.io/(user site)https://username.github.io/my-repo/(project site)- Any nested path — no config changes needed
Quick Start
# Inside your Vite project folder
npx vite-on-githubFollow the prompts, then:
- Push to GitHub
- Go to Settings → Pages → Build and deployment
- Set Source to GitHub Actions
- Done — your site deploys on every push to
main/master
CLI Reference
vite-on-github [command] [options]
Commands:
init Set up everything (default)
help Show help
Options:
-y, --yes Skip prompts
--skip-install Don't install vite-basepath
--skip-vite-config Don't patch vite.config
--skip-router Don't patch router files
--skip-ci Don't create workflow
--node <version> Node version for CI (default: 22)
--out-dir <dir> Build output (default: dist)Examples
# Interactive setup
npx vite-on-github
# Non-interactive (CI / scripts)
npx vite-on-github init -y
# Custom Node version and output dir
npx vite-on-github init --node 20 --out-dir distWhat Gets Changed
| File | Change |
|------|--------|
| package.json | Adds vite-basepath dev dependency |
| vite.config.* | Adds viteBasepath() plugin |
| src/main.* or router | Adds getBase() for React/Vue Router |
| .github/workflows/deploy.yml | GitHub Pages deploy workflow |
Existing config is patched, not replaced. Safe to run again — skips what's already done.
Programmatic API
Use in scripts or other tools:
import { init } from 'vite-on-github';
const result = await init({
cwd: '/path/to/vite-project',
yes: true,
});
console.log(result.pagesUrl); // https://user.github.io/repo/How Base Paths Work
This package uses vite-basepath under the hood:
- Build-time: sets Vite
baseto./(relative paths) - Runtime: detects the real deploy path automatically
- Routers:
getBase()returns the correctbasename/historybase
Same build works everywhere — root, subfolder, or nested path.
Demo site
The /demo folder is a full documentation site (same design as vite-basepath) adapted for vite-on-github. It deploys to GitHub Pages via .github/workflows/deploy-demo.yml.
cd demo
npm install
npm run dev # local preview
npm run build # production build + 404.html for PagesAfter pushing to GitHub, enable Settings → Pages → GitHub Actions as the source.
Requirements
- Node.js 18+
- A Vite project (
viteinpackage.json) - Git repository with GitHub remote (optional — for URL preview)
License
MIT
