fix building for PWA

This commit is contained in:
mrjvs 2023-10-25 23:04:54 +02:00
parent ca402a219d
commit 248384124a
8 changed files with 103 additions and 14 deletions

View file

@ -6,14 +6,18 @@ on:
- master - master
jobs: jobs:
build: build_pwa:
name: Build name: Build PWA
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Install Node.js - name: Install Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
@ -23,32 +27,71 @@ jobs:
- name: Install pnpm packages - name: Install pnpm packages
run: pnpm install 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 - name: Build project
run: pnpm run build run: pnpm run build
- name: Upload production-ready build files - name: Upload production-ready build files
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: production-files name: normal
path: ./dist path: ./dist
release: release:
name: Release name: Release
needs: build needs: [build, build_pwa]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Download artifact - name: Download PWA artifact
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: production-files name: pwa
path: ./dist path: ./dist_pwa
- name: Zip files - name: Zip PWA files
run: cd dist && zip -r ../movie-web.zip . 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 - name: Get version
id: package-version id: package-version
@ -65,7 +108,18 @@ jobs:
draft: false draft: false
prerelease: 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 id: upload-release-asset
uses: actions/upload-release-asset@v1 uses: actions/upload-release-asset@v1
env: env:

View file

@ -13,7 +13,11 @@ jobs:
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Install Node.js - name: Install Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:

View file

@ -15,13 +15,17 @@ jobs:
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Install Node.js - name: Install Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: 18 node-version: 18
cache: 'pnpm' cache: 'pnpm'
- name: Install pnpm packages - name: Install pnpm packages
run: pnpm install run: pnpm install
@ -36,6 +40,10 @@ jobs:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Install Node.js - name: Install Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:

1
.npmrc Normal file
View file

@ -0,0 +1 @@
shamefully-hoist=true

View file

@ -35,6 +35,7 @@
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build",
"build:pwa": "cross-env VITE_PWA_ENABLED=yes vite build",
"test": "vitest run", "test": "vitest run",
"preview": "vite preview", "preview": "vite preview",
"lint": "eslint --ext .tsx,.ts src", "lint": "eslint --ext .tsx,.ts src",
@ -75,6 +76,7 @@
"@typescript-eslint/parser": "^5.13.0", "@typescript-eslint/parser": "^5.13.0",
"@vitejs/plugin-react": "^3.1.0", "@vitejs/plugin-react": "^3.1.0",
"autoprefixer": "^10.4.13", "autoprefixer": "^10.4.13",
"cross-env": "^7.0.3",
"eslint": "^8.10.0", "eslint": "^8.10.0",
"eslint-config-airbnb": "19.0.4", "eslint-config-airbnb": "19.0.4",
"eslint-config-prettier": "^8.6.0", "eslint-config-prettier": "^8.6.0",

View file

@ -151,6 +151,9 @@ devDependencies:
autoprefixer: autoprefixer:
specifier: ^10.4.13 specifier: ^10.4.13
version: 10.4.15(postcss@8.4.29) version: 10.4.15(postcss@8.4.29)
cross-env:
specifier: ^7.0.3
version: 7.0.3
eslint: eslint:
specifier: ^8.10.0 specifier: ^8.10.0
version: 8.48.0 version: 8.48.0
@ -2840,6 +2843,14 @@ packages:
requiresBuild: true requiresBuild: true
dev: false 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: /cross-fetch@3.1.8:
resolution: {integrity: sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==} resolution: {integrity: sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==}
dependencies: dependencies:

View file

@ -3,3 +3,11 @@
X-XSS-Protection: 1; mode=block X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff X-Content-Type-Options: nosniff
Referrer-Policy: origin-when-cross-origin 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

View file

@ -1 +1,2 @@
/assets/* /assets/:splat 200
/* /index.html 200 /* /index.html 200