Skip to content

Commit

Permalink
improve deploy and manual deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
hayyi2 committed Nov 19, 2023
1 parent c5dc4b6 commit 16d0891
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: Build & Deploy

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

jobs:
deploy:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ npx shadcn-ui@latest add table
npx shadcn-ui@latest add select
```

### Deploy `gh-pages`
- change `basenameProd` in `/vite.config.ts`
- create deploy key `GITHUB_TOKEN` in github `/settings/keys`
- commit and push changes code
- setup gihub pages to branch `gh-pages`

## License

This project is licensed under the MIT License. See the [LICENSE](https://github.com/hayyi2/shadcn-sample/blob/main/LICENSE) file for details.
2 changes: 1 addition & 1 deletion src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ export const router = createBrowserRouter([
element: <NoMatch />,
},
], {
basename: '/shadcn-sample'
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
}
27 changes: 19 additions & 8 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ import path from "path"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"

export default defineConfig(({ command }) => ({
base: command === 'serve' ? '/' : '/shadcn-sample/',
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
const basenameProd = '/shadcn-sample'

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 16d0891

Please sign in to comment.