Skip to content

Commit f02287f

Browse files
committed
docs: 支持 gh-pages 部署
1 parent 5a19ee1 commit f02287f

File tree

5 files changed

+59
-3
lines changed

5 files changed

+59
-3
lines changed

.github/workflows/deploy.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: deploy
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- v*.x
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
env:
16+
VITE_APP_BASENAME: /unplugin-react-pages/
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: ./.github/actions/setup
20+
- run: pnpm run docs:build
21+
- uses: peaceiris/actions-gh-pages@v4
22+
with:
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
publish_dir: ./docs/dist
25+
publish_branch: ${{ github.ref_name }}-pages

docs/src/dts/process.env.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace NodeJS {
2+
interface ProcessEnv {
3+
/**
4+
* package name
5+
* defined in vite.config.mts
6+
*/
7+
PKG_NAME: string;
8+
9+
/**
10+
* package version
11+
* defined in vite.config.mts
12+
*/
13+
PKG_VERSION: string;
14+
15+
/**
16+
* vite 应用基础路径
17+
* Github deploy action
18+
*/
19+
VITE_APP_BASENAME?: string;
20+
21+
}
22+
}

docs/src/main.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import 'virtual:uno.css';
66
import 'virtual:svg-icons-register';
77
import App from './App';
88

9+
const basename = process.env.VITE_APP_BASENAME || '/';
10+
911
ReactDOM.createRoot(document.getElementById('root')!).render(
1012
<StrictMode>
11-
<HashRouter basename="/">
13+
<HashRouter basename={basename}>
1214
<App />
1315
</HashRouter>
1416
</StrictMode>,

docs/vite.config.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ import { defineConfig } from 'vite';
1212
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
1313
import { ViteMinifyPlugin } from 'vite-plugin-minify';
1414
import { reactPages } from '../src';
15+
import pkg from './package.json';
1516

1617
export default defineConfig({
18+
base: process.env.VITE_APP_BASENAME || '/',
1719
server: {
1820
port: 15170,
1921
},
22+
define: {
23+
'process.env.PKG_NAME': JSON.stringify(pkg.name),
24+
'process.env.PKG_VERSION': JSON.stringify(pkg.version),
25+
},
2026
plugins: [
2127
// plugins
2228
react(),

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@
5757
"test": "vitest run",
5858
"test:coverage": "vitest run --coverage",
5959
"build": "NODE_ENV=production vite build",
60-
"pre-commit": "echo 0",
61-
"pre-commit1": "pnpm run lint:type"
60+
"docs:dev": "pnpm -F 'docs' run dev",
61+
"docs:build": "pnpm -F 'docs' run build",
62+
"pre-commit": "pnpm run lint:type"
6263
},
6364
"workspaces": [
6465
"docs"

0 commit comments

Comments
 (0)