diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6fd1fbe..9dae1c8 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -15,7 +15,7 @@ jobs: build-and-deploy: runs-on: ubuntu-latest permissions: - contents: read + contents: write packages: write steps: @@ -43,34 +43,11 @@ jobs: run: bazel build //... - name: Build Site - run: pnpm run build + run: pnpm run build --base=/lit-examples/ - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to registry - uses: docker/login-action@v4 + - name: Deploy Docs + uses: peaceiris/actions-gh-pages@v4 with: - registry: ${{ env.REGISTRY }} - username: ${{ gitea.actor }} - password: ${{ secrets.GIT_TOKEN }} - - - name: Get image metadata - id: meta - run: | - NAME=$(node -p "require('./package.json').name.toLowerCase()") - OWNER=$(echo "${{ gitea.actor }}" | tr '[:upper:]' '[:lower:]') - echo "name=${NAME}" >> $GITHUB_OUTPUT - echo "owner=${OWNER}" >> $GITHUB_OUTPUT - - - name: Build and push image - uses: docker/build-push-action@v5 - with: - context: . - file: Dockerfile - push: true - tags: | - ${{ env.REGISTRY }}/${{ steps.meta.outputs.owner }}/${{ steps.meta.outputs.name }}:latest - ${{ env.REGISTRY }}/${{ steps.meta.outputs.owner }}/${{ steps.meta.outputs.name }}:${{ github.sha }} - cache-from: type=gha - cache-to: type=gha,mode=max + github_token: ${{ secrets.GITHUB_TOKEN }} + force_orphan: true + publish_dir: dist diff --git a/vite.config.js b/vite.config.js index 9fd3b16..0273086 100644 --- a/vite.config.js +++ b/vite.config.js @@ -42,7 +42,7 @@ function getHtmlEntries() { } // Vite plugin to rewrite HTML absolute assets to be subfolder-scoped -const mpaHtmlPlugin = () => { +const mpaHtmlPlugin = (base = '/') => { return { name: 'mpa-html-plugin', transformIndexHtml: { @@ -53,7 +53,7 @@ const mpaHtmlPlugin = () => { const subfolder = parts[0]; let transformed = html - // Rewrite absolute src/href paths like "/src/main.ts" to "/subfolder/src/main.ts" + // Rewrite absolute src/href paths like "/src/main.ts" to "/base/subfolder/src/main.ts" .replace(/(src|href)="\/([^"]+)"/g, (match, attr, path) => { if (path.startsWith('http://') || path.startsWith('https://')) { return match; @@ -61,7 +61,8 @@ const mpaHtmlPlugin = () => { if (path.startsWith(subfolder)) { return match; } - return `${attr}="/${subfolder}/${path}"`; + const prefix = base === '/' ? '' : base.replace(/\/$/, ''); + return `${attr}="${prefix}/${subfolder}/${path}"`; }); // Clean up platform-specific non-module scripts like capacitor.js which fail Vite build @@ -156,7 +157,8 @@ const externalizeMissingPlugin = () => { }; export default defineConfig({ - plugins: [mpaHtmlPlugin(), tsResolvePlugin(), externalizeMissingPlugin()], + base: '/lit-examples/', + plugins: [mpaHtmlPlugin('/lit-examples/'), tsResolvePlugin(), externalizeMissingPlugin()], resolve: { alias: { 'lit/decorators': 'lit/decorators.js',