To deploy a Vite app on GitHub Pages, follow these steps:
- Update Vite Config: Modify your Vite configuration to accommodate GitHub Pages deployment:
Copy code
// vite.config.js
import { defineConfig } from 'vite';
export default defineConfig({
base: '/<repository-name>/', // replace <repository-name> with your GitHub repository name
});
- Build Script: Update your package.json to include a build script that specifies the correct base URL:
"scripts": {
"build": "vite build",
"deploy": "gh-pages -d src/dist" // Ensure you have the `gh-pages` package installed
}
- Install gh-pages: Install the gh-pages npm package if not already installed:
npm install gh-pages --save-dev
- Build Your App: Build your Vite application using the build script:
npm run build
- Deploy: Deploy your app to GitHub Pages:
npm run deploy
- GitHub Repository Settings: Go to your repository settings on GitHub, find the "Pages" section, and set the source to the gh-pages branch.
This will deploy your Vite app to GitHub Pages, accessible at https://.github.io//. Make sure to replace and with your GitHub username and the repository name, respectively.