Skip to content

Commit 7c33d0e

Browse files
feat: Add GitHub Pages deployment workflow
This commit introduces a GitHub Actions workflow to automatically build and deploy the application to GitHub Pages. - Adds a new workflow file at `.github/workflows/deploy.yml` that triggers on pushes to the `main` branch. - The workflow installs dependencies, builds the application, and deploys the `dist` directory to the `gh-pages` branch. - Configures `package.json` with the `homepage` URL for correct asset pathing. - Updates `vite.config.js` with the `base` path for the same reason. - Modifies the `test` script in `package.json` to `vitest run` to prevent it from running in watch mode in CI environments.
1 parent 105189f commit 7c33d0e

File tree

4 files changed

+33
-169
lines changed

4 files changed

+33
-169
lines changed

.github/workflows/deploy.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v3
14+
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: '18'
19+
20+
- name: Install dependencies
21+
run: npm install
22+
23+
- name: Build
24+
run: npm run build
25+
26+
- name: Deploy
27+
uses: peaceiris/actions-gh-pages@v3
28+
with:
29+
github_token: ${{ secrets.GITHUB_TOKEN }}
30+
publish_dir: ./dist

package-lock.json

Lines changed: 0 additions & 168 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "codespaces-react",
3+
"homepage": "https://GYFX35.github.io/codespaces-react",
34
"version": "0.1.0",
45
"private": true,
56
"dependencies": {
@@ -19,7 +20,7 @@
1920
"start": "BROWSER=none WDS_SOCKET_PORT=0 vite --port 3000",
2021
"build": "vite build",
2122
"preview": "vite preview",
22-
"test": "vitest"
23+
"test": "vitest run"
2324
},
2425
"eslintConfig": {
2526
"extends": [

vite.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import react from "@vitejs/plugin-react";
33

44
// https://vitejs.dev/config/
55
export default defineConfig({
6+
base: "/codespaces-react/",
67
plugins: [react()],
78
test: {
89
globals: true,

0 commit comments

Comments
 (0)