Skip to content

Commit

Permalink
docs: 支持 gh-pages 部署
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudcome committed Jul 27, 2024
1 parent 5a19ee1 commit f02287f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: deploy

on:
workflow_dispatch:
push:
branches:
- v*.x

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
env:
VITE_APP_BASENAME: /unplugin-react-pages/
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: pnpm run docs:build
- uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/dist
publish_branch: ${{ github.ref_name }}-pages
22 changes: 22 additions & 0 deletions docs/src/dts/process.env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace NodeJS {
interface ProcessEnv {
/**
* package name
* defined in vite.config.mts
*/
PKG_NAME: string;

/**
* package version
* defined in vite.config.mts
*/
PKG_VERSION: string;

/**
* vite 应用基础路径
* Github deploy action
*/
VITE_APP_BASENAME?: string;

}
}
4 changes: 3 additions & 1 deletion docs/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import 'virtual:uno.css';
import 'virtual:svg-icons-register';
import App from './App';

const basename = process.env.VITE_APP_BASENAME || '/';

ReactDOM.createRoot(document.getElementById('root')!).render(
<StrictMode>
<HashRouter basename="/">
<HashRouter basename={basename}>
<App />
</HashRouter>
</StrictMode>,
Expand Down
6 changes: 6 additions & 0 deletions docs/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ import { defineConfig } from 'vite';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import { ViteMinifyPlugin } from 'vite-plugin-minify';
import { reactPages } from '../src';
import pkg from './package.json';

export default defineConfig({
base: process.env.VITE_APP_BASENAME || '/',
server: {
port: 15170,
},
define: {
'process.env.PKG_NAME': JSON.stringify(pkg.name),
'process.env.PKG_VERSION': JSON.stringify(pkg.version),
},
plugins: [
// plugins
react(),
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"build": "NODE_ENV=production vite build",
"pre-commit": "echo 0",
"pre-commit1": "pnpm run lint:type"
"docs:dev": "pnpm -F 'docs' run dev",
"docs:build": "pnpm -F 'docs' run build",
"pre-commit": "pnpm run lint:type"
},
"workspaces": [
"docs"
Expand Down

0 comments on commit f02287f

Please sign in to comment.