web deploy
parent
2cf1fb648c
commit
f7839d1dfb
@ -0,0 +1,49 @@
|
||||
name: Deploy Flutter Web to GitHub Pages
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Flutter
|
||||
uses: subosito/flutter-action@v2
|
||||
with:
|
||||
channel: stable
|
||||
|
||||
- name: Flutter version
|
||||
run: flutter --version
|
||||
|
||||
- name: Enable web and get packages
|
||||
run: |
|
||||
flutter config --enable-web
|
||||
flutter pub get
|
||||
|
||||
- name: Build Flutter web (release)
|
||||
env:
|
||||
REPO_NAME: ${{ github.event.repository.name }}
|
||||
run: |
|
||||
# Use canvaskit for better desktop rendering; adjust if needed
|
||||
flutter build web \
|
||||
--release \
|
||||
--web-renderer canvaskit \
|
||||
--base-href "/${REPO_NAME}/"
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./build/web
|
||||
# Keep history small
|
||||
force_orphan: true
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
# Flutter Web on Apache: SPA routing, caching, compression, and correct MIME types
|
||||
|
||||
<IfModule mod_rewrite.c>
|
||||
Options -MultiViews
|
||||
RewriteEngine On
|
||||
|
||||
# Serve existing files/directories directly
|
||||
RewriteCond %{REQUEST_FILENAME} -f [OR]
|
||||
RewriteCond %{REQUEST_FILENAME} -d
|
||||
RewriteRule ^ - [L]
|
||||
|
||||
# Fallback all other requests to index.html (client-side routing)
|
||||
RewriteRule ^ index.html [L]
|
||||
</IfModule>
|
||||
|
||||
# Correct MIME types (important for CanvasKit/WebAssembly and fonts)
|
||||
AddType application/wasm wasm
|
||||
AddType font/woff2 woff2
|
||||
AddType application/javascript js
|
||||
AddType text/css css
|
||||
|
||||
# Caching policy
|
||||
<IfModule mod_headers.c>
|
||||
# Long cache for static assets (Flutter uses hashed filenames)
|
||||
<FilesMatch "\.(js|css|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|wasm)$">
|
||||
Header set Cache-Control "public, max-age=31536000, immutable"
|
||||
</FilesMatch>
|
||||
|
||||
# Service configs/JSON can be cached briefly
|
||||
<FilesMatch "\.(json)$">
|
||||
Header set Cache-Control "public, max-age=3600"
|
||||
</FilesMatch>
|
||||
|
||||
# Never cache the HTML entry point
|
||||
<FilesMatch "^index\.html$">
|
||||
Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0"
|
||||
</FilesMatch>
|
||||
|
||||
# Minimal hardening
|
||||
Header always set X-Content-Type-Options "nosniff"
|
||||
Header always set Referrer-Policy "strict-origin-when-cross-origin"
|
||||
</IfModule>
|
||||
|
||||
# Compression (enable if modules are available)
|
||||
<IfModule mod_brotli.c>
|
||||
AddOutputFilterByType BROTLI_COMPRESS \
|
||||
text/html text/plain text/css application/javascript application/json application/wasm image/svg+xml
|
||||
</IfModule>
|
||||
<IfModule mod_deflate.c>
|
||||
AddOutputFilterByType DEFLATE \
|
||||
text/html text/plain text/css application/javascript application/json application/wasm image/svg+xml
|
||||
</IfModule>
|
||||
|
||||
Loading…
Reference in New Issue