【GitHub Pages】部署指南

vue项目

  1. 编辑你的 vite.config.ts 文件,加上 base 路径,设置为你的 GitHub 仓库名
js 复制代码
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// 假设你的仓库是 https://github.com/your-username/my-vue-app
export default defineConfig({
  base: '/my-vue-app/', // ← 这里改成你的仓库名
  plugins: [vue()]
})
  1. 安装部署工具
bash 复制代码
npm install gh-pages --save-dev
  1. 修改 package.json 添加脚本
js 复制代码
{
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "deploy": "gh-pages -d dist"
  }
}
  1. 把打包后的 dist/ 目录部署到你 GitHub 仓库的 gh-pages 分支。
    源码上传: 上传到主分支(如 main 或 master)
    构建产物上传: dist/ 目录上传到 gh-pages 分支
bash 复制代码
npm run build
npm run deploy

# 1. 构建项目
yarn build   # 产物在 dist/

# 2. 安装 gh-pages 工具(仅第一次)
yarn add -D gh-pages

# 3. 发布 dist 到 gh-pages 分支
npx gh-pages -d dist

#启动一个本地静态服务器,预览 dist 目录中的构建结果
npx serve dist --port 5173 --single 
## single 适用于SPA 所有404重定向到index.html
  1. 设置 GitHub Pages
    打开你的 GitHub 仓库
    点右上角的「⚙️ Settings」
    左侧点击「Pages」
    选择 gh-pages 分支,目录为 / (root)
    保存设置
    稍等几分钟,你的网站就可以通过这个地址访问:
    https://your-username.github.io/my-vue-app/

公有仓库才能免费使用github pages

相关推荐
Moonbit2 小时前
月报 Vol.04 : 新增 async test 与 async fn main 语法,新增 lexmatch 表达式
后端·github·编程语言
逛逛GitHub3 小时前
发现 4 个贼好玩的 GitHub 项目,相当给劲儿。
github
悟能不能悟5 小时前
用cmd命令修改适配器ip
网络·tcp/ip·github
whysqwhw5 小时前
kuiklyui core-ksp ios
github
whysqwhw5 小时前
kuiklyui core-ksp 鸿蒙
github
CoderJia程序员甲5 小时前
GitHub 热榜项目 - 日榜(2025-10-12)
ai·github·开源项目·github热榜
whysqwhw6 小时前
kuikly core-ksp 安卓
github
Tfly__7 小时前
Ubuntu 20.04 安装Aerial Gym Simulator - 基于 Gym 的无人机强化学习仿真器
linux·人工智能·ubuntu·github·无人机·强化学习·运动规划
CoderJia程序员甲8 小时前
GitHub 热榜项目 - 日榜(2025-10-13)
ai·开源·大模型·github·ai教程
uhakadotcom9 小时前
coze的AsyncTokenAuth和coze的TokenAuth有哪些使用的差异?
后端·面试·github