From 248384124a31b20bd8932df89b3fad1fe0161685 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Wed, 25 Oct 2023 23:04:54 +0200 Subject: [PATCH] fix building for PWA --- .github/workflows/deploying.yml | 76 +++++++++++++++++++++++---- .github/workflows/docs.yml | 6 ++- .github/workflows/linting_testing.yml | 12 ++++- .npmrc | 1 + package.json | 2 + pnpm-lock.yaml | 11 ++++ public/_headers | 8 +++ public/_redirects | 1 + 8 files changed, 103 insertions(+), 14 deletions(-) create mode 100644 .npmrc diff --git a/.github/workflows/deploying.yml b/.github/workflows/deploying.yml index 79a664aa..cd8a6b57 100644 --- a/.github/workflows/deploying.yml +++ b/.github/workflows/deploying.yml @@ -6,14 +6,18 @@ on: - master jobs: - build: - name: Build + build_pwa: + name: Build PWA runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - + + - uses: pnpm/action-setup@v2 + with: + version: 8 + - name: Install Node.js uses: actions/setup-node@v3 with: @@ -23,32 +27,71 @@ jobs: - name: Install pnpm packages run: pnpm install + - name: Build project + run: pnpm run build:pwa + + - name: Upload production-ready build files + uses: actions/upload-artifact@v3 + with: + name: pwa + path: ./dist + + build: + name: Build + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - uses: pnpm/action-setup@v2 + with: + version: 8 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'pnpm' + + - name: Install pnpm packages + run: pnpm install + - name: Build project run: pnpm run build - name: Upload production-ready build files uses: actions/upload-artifact@v3 with: - name: production-files + name: normal path: ./dist release: name: Release - needs: build + needs: [build, build_pwa] runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - - name: Download artifact + - name: Download PWA artifact uses: actions/download-artifact@v3 with: - name: production-files - path: ./dist + name: pwa + path: ./dist_pwa - - name: Zip files - run: cd dist && zip -r ../movie-web.zip . + - name: Zip PWA files + run: cd dist_pwa && zip -r ../movie-web.pwa.zip . + + - name: Download normal artifact + uses: actions/download-artifact@v3 + with: + name: normal + path: ./dist_normal + + - name: Zip normal files + run: cd dist_normal && zip -r ../movie-web.zip . - name: Get version id: package-version @@ -65,7 +108,18 @@ jobs: draft: false prerelease: false - - name: Upload Release Asset + - name: Upload release (PWA) + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./movie-web.pwa.zip + asset_name: movie-web.pwa.zip + asset_content_type: application/zip + + - name: Upload Release (Normal) id: upload-release-asset uses: actions/upload-release-asset@v1 env: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 77bcad9c..f73ab3ff 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -13,7 +13,11 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 - + + - uses: pnpm/action-setup@v2 + with: + version: 8 + - name: Install Node.js uses: actions/setup-node@v3 with: diff --git a/.github/workflows/linting_testing.yml b/.github/workflows/linting_testing.yml index 59b17086..4b2c2caa 100644 --- a/.github/workflows/linting_testing.yml +++ b/.github/workflows/linting_testing.yml @@ -15,13 +15,17 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 - + + - uses: pnpm/action-setup@v2 + with: + version: 8 + - name: Install Node.js uses: actions/setup-node@v3 with: node-version: 18 cache: 'pnpm' - + - name: Install pnpm packages run: pnpm install @@ -36,6 +40,10 @@ jobs: - name: Checkout code uses: actions/checkout@v3 + - uses: pnpm/action-setup@v2 + with: + version: 8 + - name: Install Node.js uses: actions/setup-node@v3 with: diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..bf2e7648 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +shamefully-hoist=true diff --git a/package.json b/package.json index da44b9e6..89d24cff 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "scripts": { "dev": "vite", "build": "vite build", + "build:pwa": "cross-env VITE_PWA_ENABLED=yes vite build", "test": "vitest run", "preview": "vite preview", "lint": "eslint --ext .tsx,.ts src", @@ -75,6 +76,7 @@ "@typescript-eslint/parser": "^5.13.0", "@vitejs/plugin-react": "^3.1.0", "autoprefixer": "^10.4.13", + "cross-env": "^7.0.3", "eslint": "^8.10.0", "eslint-config-airbnb": "19.0.4", "eslint-config-prettier": "^8.6.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2fe6bc46..39600aae 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -151,6 +151,9 @@ devDependencies: autoprefixer: specifier: ^10.4.13 version: 10.4.15(postcss@8.4.29) + cross-env: + specifier: ^7.0.3 + version: 7.0.3 eslint: specifier: ^8.10.0 version: 8.48.0 @@ -2840,6 +2843,14 @@ packages: requiresBuild: true dev: false + /cross-env@7.0.3: + resolution: {integrity: sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==} + engines: {node: '>=10.14', npm: '>=6', yarn: '>=1'} + hasBin: true + dependencies: + cross-spawn: 7.0.3 + dev: true + /cross-fetch@3.1.8: resolution: {integrity: sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==} dependencies: diff --git a/public/_headers b/public/_headers index 1216e42d..0f4e3f29 100644 --- a/public/_headers +++ b/public/_headers @@ -3,3 +3,11 @@ X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff Referrer-Policy: origin-when-cross-origin + Cache-Control: public, max-age=0, s-maxage=0, must-revalidate + +/manifest.webmanifest + Content-Type: application/manifest+json + +# assets get a long cache instead of no cache +/assets/* + Cache-Control: public, max-age=31536000, s-maxage=31536000, immutable diff --git a/public/_redirects b/public/_redirects index 7797f7c6..ee9870cf 100644 --- a/public/_redirects +++ b/public/_redirects @@ -1 +1,2 @@ +/assets/* /assets/:splat 200 /* /index.html 200