Skip to content

Commit c1b828c

Browse files
committed
fix deploy
1 parent d756782 commit c1b828c

File tree

2 files changed

+60
-27
lines changed

2 files changed

+60
-27
lines changed

.github/workflows/deploy.yml

+38-22
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,47 @@
1-
name: Deploy to GitHub Pages
1+
name: Build and deploy
22

33
on:
4+
# Runs on pushes targeting the default branch
45
push:
5-
branches:
6-
- main # Set this to your default branch
6+
branches: ["main"]
77

8-
jobs:
9-
deploy:
10-
runs-on: ubuntu-latest
11-
permissions:
12-
contents: write # This is required for the deployment to work
13-
steps:
14-
- uses: actions/checkout@v3
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
1510

16-
- name: Setup Node
17-
uses: actions/setup-node@v3
18-
with:
19-
node-version: '20' # Use the Node.js version specified in your package.json
11+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
2016

21-
- name: Install dependencies
22-
run: npm ci
17+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
18+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
19+
concurrency:
20+
group: "pages"
21+
cancel-in-progress: false
2322

24-
- name: Build
25-
run: npm run build
2623

27-
- name: Deploy
28-
uses: peaceiris/actions-gh-pages@v3
24+
jobs:
25+
# Single deploy job since we're just deploying
26+
build-and-deploy:
27+
environment:
28+
name: github-pages
29+
url: ${{ steps.deployment.outputs.page_url }}
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
- name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built.
35+
run: |
36+
npm ci
37+
npm run build
38+
- name: Setup Pages
39+
uses: actions/configure-pages@v4
40+
- name: Upload artifact
41+
uses: actions/upload-pages-artifact@v3
2942
with:
30-
github_token: ${{ secrets.GITHUB_TOKEN }}
31-
publish_dir: ./build/client # Adjust this to your build output directory
43+
# Upload entire repository
44+
path: 'build/client'
45+
- name: Deploy to GitHub Pages
46+
id: deployment
47+
uses: actions/deploy-pages@v4

vite.config.ts

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
import { vitePlugin as remix } from "@remix-run/dev";
22
import { defineConfig } from "vite";
33
import tsconfigPaths from "vite-tsconfig-paths";
4+
import { copyFileSync } from "node:fs";
5+
import { join } from "node:path";
46

57
export default defineConfig({
8+
base: "/remix-gh-pages/",
69
plugins: [
710
remix({
8-
future: {
9-
v3_fetcherPersist: true,
10-
v3_relativeSplatPath: true,
11-
v3_throwAbortReason: true,
11+
ssr: false,
12+
basename: "/remix-gh-pages/",
13+
buildEnd(args) {
14+
if (!args.viteConfig.isProduction) return;
15+
16+
// When deploying to GitHub Pages, if you navigate from / to another
17+
// route and refresh the tab, it will show the default GH Pages 404
18+
// page. This happens because GH Pages is not configured to send all
19+
// traffic to the index.html where we can load our client-side JS.
20+
// To fix this, we can create a 404.html file that contains the same
21+
// content as index.html. This way, when the user refreshes the page,
22+
// GH Pages will serve our 404.html and everything will work as
23+
//expected.
24+
const buildPath = args.viteConfig.build.outDir;
25+
copyFileSync(
26+
join(buildPath, "index.html"),
27+
join(buildPath, "404.html"),
28+
);
1229
},
1330
}),
1431
tsconfigPaths(),
1532
],
16-
});
33+
});

0 commit comments

Comments
 (0)