Skip to content

Commit

Permalink
github action build & deploy gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
hayyi2 committed Nov 19, 2023
1 parent c339857 commit 167a42a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build & Deploy

on:
workflow_dispatch:
# on:
# push:
# branches: ["main"]

jobs:
deploy:
runs-on: ubuntu-latest

permissions:
contents: write

strategy:
matrix:
node-version: ["20.9.0"]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install packages
run: npm i

- name: Run npm build
run: npm run build

- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
publish_dir: dist
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ export const router = createBrowserRouter([
path: "*",
element: <NoMatch />,
},
])
], {
basename: global.basename
})
4 changes: 4 additions & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/// <reference types="vite/client" />

declare const global: {
basename: string
}
24 changes: 18 additions & 6 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@ import path from "path"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"

export default defineConfig({
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
const basenameProd = '/react-shadcn-starter'

export default defineConfig(({ command }) => {
const isProd = command === 'build'

return {
base: isProd ? basenameProd : '',
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
define: {
global: {
basename: isProd ? basenameProd : '',
},
},
},
}
})

0 comments on commit 167a42a

Please sign in to comment.