diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..ed00341 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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 diff --git a/docs/src/dts/process.env.d.ts b/docs/src/dts/process.env.d.ts new file mode 100644 index 0000000..933a777 --- /dev/null +++ b/docs/src/dts/process.env.d.ts @@ -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; + + } +} diff --git a/docs/src/main.tsx b/docs/src/main.tsx index 6d41598..726284f 100644 --- a/docs/src/main.tsx +++ b/docs/src/main.tsx @@ -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( - + , diff --git a/docs/vite.config.mts b/docs/vite.config.mts index fd520c2..adf13a8 100644 --- a/docs/vite.config.mts +++ b/docs/vite.config.mts @@ -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(), diff --git a/package.json b/package.json index 8794998..13d1463 100644 --- a/package.json +++ b/package.json @@ -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"