百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
V

vite-deploy-demo

> 编程语言
开源

使用 GitHub Actions 将 Vite 应用部署到 GitHub 页面

384 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

使用 GitHub Actions 将 Vite 应用部署到 GitHub 页面

Deploy Vite app to GitHub Pages using GitHub Actions

Video tutorial

Step-by-step instructions

Scaffold a new Vite app and init git

bash
# Create new Vite project using React template
npm create vite@latest vite-project -- --template react

# Install dependencies and start development server
cd vite-project
npm install
npm run dev

If the project is working fine, let's init a new git repository.

bash
git init
git add .
git commit -m "init vite project"
  • https://vitejs.dev/guide/#scaffolding-your-first-vite-project

Create a new GitHub repository

Go to https://github.com/new and create a new repository.

❗️ Make sure Public is selected if you don't have a premium account. Otherwise, you won't be able to host your app using GitHub pages.

Once the repo is created, copy and paste the instructions similar to these to your terminal

bash
git remote add origin [email protected]:sitek94/vite-deploy-demo.git
git branch -M main
git push -u origin main

Create deployment workflow

Create a new file: .github/workflows/deploy.yml and paste the following code:

…

This workflow will run on every push to the main branch. It will first build the project, and then deploy it to GitHub pages.

Test deployment workflow

Commit deployment workflow and push the changes to GitHub.

bash
git add .
git commit -m "add deploy workflow"
git push

When you go, to Actions and click on the recent workflow, you should see that it failed, because of missing permissions:

Ensure Actions have write permission

To fix that, go to Actions Settings, select Read and write permissions and hit Save:

Basically, our action is going to modify the repo, so it needs the write permission.

Go back to Actions, click on failed workflow and in the top-right corner click on Re-run failed jobs

After job run, you should be able to see a new branch gh-pages created in your repository.

Enable GitHub pages

To host the app, go to Pages Settings, set Source to gh-pages, and hit Save.

After a while your app should be deployed and be available at the link displayed in Pages Settings. If you want to follow the deployment process, go to Actions and pages-build-deployment workflow:

Once deployment is done, visit the app at: https://.github.io/REPO_NAME

Fix assets links

You will see that something is not right, because instead of there is a blank screen. When you inspect it, you will see that some files were not found.

This is happening, because of the subdirectory-like URL structure GitHub uses for Project Pages. Asset links are referencing the files in the domain root, whereas our project is located in /vite-deploy/demo. This is how the links should look like:

❌ Bad
https://sitek94.github.io/assets/favicon.17e50649.svg

✅ Good
https://sitek94.github.io/vite-deploy-demo/assets/favicon.17e50649.svg

Fortunately, there is a very easy fix for this. Add the following line in vite.config.js:

diff
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
   plugins: [react()],
+  base: '/vite-deploy-demo/'
})

Now, asset links will have a correct path, so commit the changes, push the code, wait for the deploy to finish and see it for yourself!

Final

FAQ

  • How to setup custom domain?

Resources

  • Vite
  • GitHub Pages
  • GitHub Actions

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptgh-actionsgh-pagesvite

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言