diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
new file mode 100644
index 0000000..d5dadc4
--- /dev/null
+++ b/.github/workflows/deploy.yml
@@ -0,0 +1,63 @@
+name: Deploy Demo to GitHub Pages
+
+on:
+ push:
+ branches: [ main ]
+ pull_request:
+ branches: [ main ]
+
+permissions:
+ contents: read
+ pages: write
+ id-token: write
+
+concurrency:
+ group: "pages"
+ cancel-in-progress: false
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Setup pnpm
+ uses: pnpm/action-setup@v2
+ with:
+ version: latest
+
+ - name: Setup Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: '18'
+ cache: 'pnpm'
+
+ - name: Install dependencies
+ run: pnpm install --frozen-lockfile
+
+ - name: Build package with types
+ run: pnpm --filter tps-controls build
+
+ - name: Build demo for GitHub Pages
+ run: pnpm --filter demo build:github
+
+ - name: Create .nojekyll file
+ run: touch demo/dist/.nojekyll
+
+ - name: Upload artifact
+ uses: actions/upload-pages-artifact@v3
+ with:
+ path: demo/dist
+
+ deploy:
+ environment:
+ name: github-pages
+ url: ${{ steps.deployment.outputs.page_url }}
+ runs-on: ubuntu-latest
+ needs: build
+ if: github.ref == 'refs/heads/main'
+ steps:
+ - name: Deploy to GitHub Pages
+ id: deployment
+ uses: actions/deploy-pages@v4
diff --git a/demo/package.json b/demo/package.json
index 8df08f6..6c38309 100644
--- a/demo/package.json
+++ b/demo/package.json
@@ -6,6 +6,8 @@
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
+ "build:github": "vite build --base=/TPS-Controls/",
+ "build:github-with-types": "tsc -b && vite build --base=/TPS-Controls/",
"preview": "vite preview"
},
"dependencies": {
diff --git a/demo/src/App.tsx b/demo/src/App.tsx
index 570d7c8..c0fc2c1 100644
--- a/demo/src/App.tsx
+++ b/demo/src/App.tsx
@@ -5,6 +5,12 @@ import { Player } from "tps-controls"
import { Physics } from '@react-three/rapier';
import { Environment } from './Environment';
+// Get the correct asset path for GitHub Pages deployment
+const getAssetPath = (path: string) => {
+ const base = import.meta.env.BASE_URL || '/'
+ return base + path.replace(/^\//, '')
+}
+
function App() {
@@ -13,7 +19,7 @@ function App() {
{/* Player with shadow casting */}
-
+
diff --git a/demo/vite.config.ts b/demo/vite.config.ts
index 8b0f57b..735897e 100644
--- a/demo/vite.config.ts
+++ b/demo/vite.config.ts
@@ -2,6 +2,11 @@ import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
-export default defineConfig({
+export default defineConfig(({ command, mode }) => ({
plugins: [react()],
-})
+ base: mode === 'production' ? '/TPS-Controls/' : '/',
+ build: {
+ outDir: 'dist',
+ assetsDir: 'assets',
+ },
+}))
diff --git a/package.json b/package.json
index 0dc7e36..2de0df3 100644
--- a/package.json
+++ b/package.json
@@ -8,6 +8,8 @@
"dev:watch": "concurrently \"pnpm --filter tps-controls dev\" \"pnpm --filter demo dev\"",
"build": "pnpm --filter tps-controls build",
"build:demo": "pnpm --filter demo build",
+ "build:github": "pnpm run build && pnpm --filter demo build:github",
+ "deploy:github": "pnpm run build:github && echo '✅ Demo built for GitHub Pages! Push to main branch to deploy.'",
"publish:package": "pnpm run build && pnpm --filter tps-controls publish",
"test": "pnpm --filter '*' test",
"lint": "eslint . --ext .ts,.tsx",