Skip to content

Commit 2d21ba4

Browse files
authored
Initial commit
0 parents  commit 2d21ba4

10 files changed

Lines changed: 1218 additions & 0 deletions

File tree

.github/workflows/main.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# .github/workflows/deploy-pages.yml
2+
name: Deploy static content to Pages
3+
4+
on:
5+
push:
6+
branches: [main]
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: pages
16+
cancel-in-progress: true
17+
18+
jobs:
19+
deploy:
20+
environment:
21+
name: github-pages
22+
url: ${{ steps.deployment.outputs.page_url }}
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
# ---------- 1) Check if Pages is enabled ----------
30+
- name: Detect GitHub Pages status
31+
id: pages_status
32+
run: |
33+
set -e
34+
http_status=$(curl -s -o /dev/null -w "%{http_code}" \
35+
-H "Authorization: Bearer ${{ github.token }}" \
36+
-H "Accept: application/vnd.github+json" \
37+
https://api.github.com/repos/${{ github.repository }}/pages)
38+
39+
if [ "$http_status" = "200" ]; then
40+
echo "✅ Pages already enabled."
41+
echo "deploy=yes" >> "$GITHUB_OUTPUT"
42+
else
43+
echo "::notice ::GitHub Pages is not enabled for this repository yet."
44+
echo "::notice ::Enable it under Settings → Pages (select **GitHub Actions** as the source) and rerun the workflow."
45+
echo "deploy=no" >> "$GITHUB_OUTPUT"
46+
fi
47+
48+
# ---------- 2) Stop early when Pages is disabled ----------
49+
- name: Early‑exit (no deploy needed)
50+
if: steps.pages_status.outputs.deploy == 'no'
51+
run: echo "Skipping build & deploy because Pages is disabled."
52+
# Workflow ends successfully here when deploy=no
53+
continue-on-error: false
54+
55+
# ---------- 3) Normal build & deploy path ----------
56+
- name: Set up Node
57+
if: steps.pages_status.outputs.deploy == 'yes'
58+
uses: actions/setup-node@v4
59+
with:
60+
node-version: lts/*
61+
cache: npm
62+
63+
- name: Install dependencies
64+
if: steps.pages_status.outputs.deploy == 'yes'
65+
run: npm ci
66+
67+
- name: Build
68+
if: steps.pages_status.outputs.deploy == 'yes'
69+
run: npm run build
70+
71+
- name: Setup Pages
72+
if: steps.pages_status.outputs.deploy == 'yes'
73+
uses: actions/configure-pages@v5
74+
75+
- name: Upload artifact
76+
if: steps.pages_status.outputs.deploy == 'yes'
77+
uses: actions/upload-pages-artifact@v3
78+
with:
79+
path: ./dist
80+
81+
- name: Deploy to GitHub Pages
82+
if: steps.pages_status.outputs.deploy == 'yes'
83+
id: deployment
84+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# github-pages-vite
2+
Template for using Vite with GitHub Pages
3+
4+
## GitHub Action
5+
This template includes a GitHub Action workflow at `.github/workflows/main.yml`. The Action builds the Vite app to `/dest`. It then deploys the contents of `/dest` to production at `https://user.github.io/repository`
6+
7+
## Vite Config
8+
When deploying a repository to GitHub Pages, the repository name will by default become part of the URL path. (e.g. `https://user.github.io/repository` ) Vite has been configured in `vite.config.js` in order to dynamically understand this path based on a flag in the GitHub Actions build environment. During local development, Vite will assume a root of `/` but when building for produciton, it will instead use `/repository/` as the root.
9+
10+
## How to Use
11+
- Make a new repository from this template.
12+
- In the Rpository Settings, go to `Pages`
13+
- Under `Build and Deployment` change the `Source` to `GitHub Actions`
14+
- Now, when you push changes they will be auto deployed to `https://user.github.io/repository`

index.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<link
7+
rel="icon"
8+
type="image/svg+xml"
9+
href="/play.svg"
10+
/>
11+
<meta
12+
name="viewport"
13+
content="width=device-width, initial-scale=1.0"
14+
/>
15+
<title>Vite App</title>
16+
</head>
17+
18+
<body>
19+
<div id="app"> </div>
20+
21+
<script
22+
type="module"
23+
src="/src/main.js"
24+
></script>
25+
</body>
26+
27+
</html>

0 commit comments

Comments
 (0)