forked from trent_larson/crowd-funder-for-time-pwa
Remove manual service worker registration; rely on VitePWA auto-registration
- Deleted src/registerServiceWorker.ts and all related imports - Cleaned up WebPlatformService and main.web.ts to remove manual SW logic - Updated VitePWA config for correct dev/prod SW handling - Fixed missing FontAwesome download icon in PWA prompt - Updated docs to reflect new PWA registration approach PWA now works reliably in all web environments with zero manual SW code.
This commit is contained in:
@@ -149,7 +149,7 @@ export function createBuildConfig(mode: string) {
|
|||||||
return {
|
return {
|
||||||
define: {
|
define: {
|
||||||
'process.env.VITE_PLATFORM': JSON.stringify(mode),
|
'process.env.VITE_PLATFORM': JSON.stringify(mode),
|
||||||
'process.env.VITE_PWA_ENABLED': JSON.stringify(!isNative),
|
// PWA is automatically enabled for web platforms via build configuration
|
||||||
__IS_MOBILE__: JSON.stringify(isCapacitor),
|
__IS_MOBILE__: JSON.stringify(isCapacitor),
|
||||||
__USE_QR_READER__: JSON.stringify(!isCapacitor)
|
__USE_QR_READER__: JSON.stringify(!isCapacitor)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
VITE_DEFAULT_ENDORSER_API_SERVER=http://127.0.0.1:3000
|
VITE_DEFAULT_ENDORSER_API_SERVER=http://127.0.0.1:3000
|
||||||
VITE_PWA_ENABLED=true
|
|
||||||
|
|||||||
@@ -10,4 +10,3 @@ VITE_DEFAULT_ENDORSER_API_SERVER=https://api.endorser.ch
|
|||||||
VITE_DEFAULT_IMAGE_API_SERVER=https://image-api.timesafari.app
|
VITE_DEFAULT_IMAGE_API_SERVER=https://image-api.timesafari.app
|
||||||
VITE_DEFAULT_PARTNER_API_SERVER=https://partner-api.endorser.ch
|
VITE_DEFAULT_PARTNER_API_SERVER=https://partner-api.endorser.ch
|
||||||
VITE_DEFAULT_PUSH_SERVER=https://timesafari.app
|
VITE_DEFAULT_PUSH_SERVER=https://timesafari.app
|
||||||
VITE_PWA_ENABLED=true
|
|
||||||
|
|||||||
@@ -11,4 +11,3 @@ VITE_DEFAULT_IMAGE_API_SERVER=https://test-image-api.timesafari.app
|
|||||||
VITE_DEFAULT_PARTNER_API_SERVER=https://test-partner-api.endorser.ch
|
VITE_DEFAULT_PARTNER_API_SERVER=https://test-partner-api.endorser.ch
|
||||||
VITE_DEFAULT_PUSH_SERVER=https://test.timesafari.app
|
VITE_DEFAULT_PUSH_SERVER=https://test.timesafari.app
|
||||||
VITE_PASSKEYS_ENABLED=true
|
VITE_PASSKEYS_ENABLED=true
|
||||||
VITE_PWA_ENABLED=false
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ define(['./workbox-54d0af47'], (function (workbox) { 'use strict';
|
|||||||
"revision": "3ca0b8505b4bec776b69afdba2768812"
|
"revision": "3ca0b8505b4bec776b69afdba2768812"
|
||||||
}, {
|
}, {
|
||||||
"url": "index.html",
|
"url": "index.html",
|
||||||
"revision": "0.qptlo5ufc6o"
|
"revision": "0.6n0ha79iivo"
|
||||||
}], {});
|
}], {});
|
||||||
workbox.cleanupOutdatedCaches();
|
workbox.cleanupOutdatedCaches();
|
||||||
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
|
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -168,7 +168,7 @@ export async function createBuildConfig(mode: string) {
|
|||||||
return defineConfig({
|
return defineConfig({
|
||||||
define: {
|
define: {
|
||||||
'process.env.VITE_PLATFORM': JSON.stringify(mode),
|
'process.env.VITE_PLATFORM': JSON.stringify(mode),
|
||||||
'process.env.VITE_PWA_ENABLED': JSON.stringify(!isNative),
|
// PWA is automatically enabled for web platforms via build configuration
|
||||||
__IS_MOBILE__: JSON.stringify(isCapacitor),
|
__IS_MOBILE__: JSON.stringify(isCapacitor),
|
||||||
__USE_QR_READER__: JSON.stringify(!isCapacitor)
|
__USE_QR_READER__: JSON.stringify(!isCapacitor)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ docker build --build-arg BUILD_MODE=development -t timesafari:dev .
|
|||||||
docker build \
|
docker build \
|
||||||
--build-arg BUILD_MODE=staging \
|
--build-arg BUILD_MODE=staging \
|
||||||
--build-arg NODE_ENV=staging \
|
--build-arg NODE_ENV=staging \
|
||||||
--build-arg VITE_PWA_ENABLED=true \
|
|
||||||
-t timesafari:custom .
|
-t timesafari:custom .
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -103,8 +103,7 @@ The Dockerfile supports these build arguments:
|
|||||||
| `BUILD_MODE` | `production` | Build mode: development, staging, or production |
|
| `BUILD_MODE` | `production` | Build mode: development, staging, or production |
|
||||||
| `NODE_ENV` | `production` | Node.js environment |
|
| `NODE_ENV` | `production` | Node.js environment |
|
||||||
| `VITE_PLATFORM` | `web` | Vite platform type |
|
| `VITE_PLATFORM` | `web` | Vite platform type |
|
||||||
| `VITE_PWA_ENABLED` | `true` | Enable PWA features |
|
| PWA | `enabled` | Automatically enabled for web platforms |
|
||||||
| `VITE_DISABLE_PWA` | `false` | Disable PWA features |
|
|
||||||
|
|
||||||
### Environment Variables
|
### Environment Variables
|
||||||
|
|
||||||
@@ -115,8 +114,7 @@ Docker Compose supports these environment variables:
|
|||||||
| `BUILD_MODE` | `production` | Build mode |
|
| `BUILD_MODE` | `production` | Build mode |
|
||||||
| `NODE_ENV` | `production` | Node environment |
|
| `NODE_ENV` | `production` | Node environment |
|
||||||
| `VITE_PLATFORM` | `web` | Vite platform |
|
| `VITE_PLATFORM` | `web` | Vite platform |
|
||||||
| `VITE_PWA_ENABLED` | `true` | Enable PWA |
|
| PWA | `enabled` | Automatically enabled for web platforms |
|
||||||
| `VITE_DISABLE_PWA` | `false` | Disable PWA |
|
|
||||||
| `DEV_PORT` | `5173` | Development port |
|
| `DEV_PORT` | `5173` | Development port |
|
||||||
| `STAGING_PORT` | `8080` | Staging port |
|
| `STAGING_PORT` | `8080` | Staging port |
|
||||||
| `PROD_PORT` | `80` | Production port |
|
| `PROD_PORT` | `80` | Production port |
|
||||||
@@ -214,7 +212,7 @@ BUILD_MODE=staging NODE_ENV=staging ./docker/run.sh custom
|
|||||||
docker build \
|
docker build \
|
||||||
--build-arg BUILD_MODE=staging \
|
--build-arg BUILD_MODE=staging \
|
||||||
--build-arg NODE_ENV=staging \
|
--build-arg NODE_ENV=staging \
|
||||||
--build-arg VITE_PWA_ENABLED=false \
|
|
||||||
-t timesafari:staging-no-pwa .
|
-t timesafari:staging-no-pwa .
|
||||||
|
|
||||||
# Run with custom configuration
|
# Run with custom configuration
|
||||||
|
|||||||
@@ -13,8 +13,7 @@
|
|||||||
# BUILD_MODE: development, staging, or production
|
# BUILD_MODE: development, staging, or production
|
||||||
# NODE_ENV: node environment
|
# NODE_ENV: node environment
|
||||||
# VITE_PLATFORM: vite platform
|
# VITE_PLATFORM: vite platform
|
||||||
# VITE_PWA_ENABLED: enable PWA
|
# PWA: automatically enabled for web platforms
|
||||||
# VITE_DISABLE_PWA: disable PWA
|
|
||||||
# PORT: port to expose
|
# PORT: port to expose
|
||||||
# ENV_FILE: environment file to use
|
# ENV_FILE: environment file to use
|
||||||
|
|
||||||
@@ -72,8 +71,7 @@ show_usage() {
|
|||||||
echo " BUILD_MODE: development, staging, or production"
|
echo " BUILD_MODE: development, staging, or production"
|
||||||
echo " NODE_ENV: node environment"
|
echo " NODE_ENV: node environment"
|
||||||
echo " VITE_PLATFORM: vite platform"
|
echo " VITE_PLATFORM: vite platform"
|
||||||
echo " VITE_PWA_ENABLED: enable PWA"
|
echo " PWA: automatically enabled for web platforms"
|
||||||
echo " VITE_DISABLE_PWA: disable PWA"
|
|
||||||
echo " PORT: port to expose"
|
echo " PORT: port to expose"
|
||||||
echo " ENV_FILE: environment file to use"
|
echo " ENV_FILE: environment file to use"
|
||||||
}
|
}
|
||||||
@@ -88,8 +86,7 @@ show_build_args() {
|
|||||||
echo " BUILD_MODE: development"
|
echo " BUILD_MODE: development"
|
||||||
echo " NODE_ENV: development"
|
echo " NODE_ENV: development"
|
||||||
echo " VITE_PLATFORM: web"
|
echo " VITE_PLATFORM: web"
|
||||||
echo " VITE_PWA_ENABLED: true"
|
echo " PWA: enabled (web platform)"
|
||||||
echo " VITE_DISABLE_PWA: false"
|
|
||||||
echo " Target: development"
|
echo " Target: development"
|
||||||
echo " Port: 5173"
|
echo " Port: 5173"
|
||||||
;;
|
;;
|
||||||
@@ -97,8 +94,7 @@ show_build_args() {
|
|||||||
echo " BUILD_MODE: staging"
|
echo " BUILD_MODE: staging"
|
||||||
echo " NODE_ENV: staging"
|
echo " NODE_ENV: staging"
|
||||||
echo " VITE_PLATFORM: web"
|
echo " VITE_PLATFORM: web"
|
||||||
echo " VITE_PWA_ENABLED: true"
|
echo " PWA: enabled (web platform)"
|
||||||
echo " VITE_DISABLE_PWA: false"
|
|
||||||
echo " Target: staging"
|
echo " Target: staging"
|
||||||
echo " Port: 80 (mapped to 8080)"
|
echo " Port: 80 (mapped to 8080)"
|
||||||
;;
|
;;
|
||||||
@@ -106,8 +102,7 @@ show_build_args() {
|
|||||||
echo " BUILD_MODE: production"
|
echo " BUILD_MODE: production"
|
||||||
echo " NODE_ENV: production"
|
echo " NODE_ENV: production"
|
||||||
echo " VITE_PLATFORM: web"
|
echo " VITE_PLATFORM: web"
|
||||||
echo " VITE_PWA_ENABLED: true"
|
echo " PWA: enabled (web platform)"
|
||||||
echo " VITE_DISABLE_PWA: false"
|
|
||||||
echo " Target: production"
|
echo " Target: production"
|
||||||
echo " Port: 80"
|
echo " Port: 80"
|
||||||
;;
|
;;
|
||||||
@@ -115,8 +110,7 @@ show_build_args() {
|
|||||||
echo " BUILD_MODE: \${BUILD_MODE:-production}"
|
echo " BUILD_MODE: \${BUILD_MODE:-production}"
|
||||||
echo " NODE_ENV: \${NODE_ENV:-production}"
|
echo " NODE_ENV: \${NODE_ENV:-production}"
|
||||||
echo " VITE_PLATFORM: \${VITE_PLATFORM:-web}"
|
echo " VITE_PLATFORM: \${VITE_PLATFORM:-web}"
|
||||||
echo " VITE_PWA_ENABLED: \${VITE_PWA_ENABLED:-true}"
|
echo " PWA: enabled for web platforms"
|
||||||
echo " VITE_DISABLE_PWA: \${VITE_DISABLE_PWA:-false}"
|
|
||||||
echo " Target: \${BUILD_TARGET:-production}"
|
echo " Target: \${BUILD_TARGET:-production}"
|
||||||
echo " Port: \${CUSTOM_PORT:-8080}:\${CUSTOM_INTERNAL_PORT:-80}"
|
echo " Port: \${CUSTOM_PORT:-8080}:\${CUSTOM_INTERNAL_PORT:-80}"
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ All build scripts follow a consistent pattern:
|
|||||||
```bash
|
```bash
|
||||||
# Set platform-specific environment variables
|
# Set platform-specific environment variables
|
||||||
VITE_PLATFORM=<platform>
|
VITE_PLATFORM=<platform>
|
||||||
VITE_PWA_ENABLED=<true/false>
|
PWA: automatically enabled for web platforms
|
||||||
VITE_GIT_HASH=<git-commit-hash>
|
VITE_GIT_HASH=<git-commit-hash>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -212,8 +212,7 @@ All build systems use consistent environment variable patterns:
|
|||||||
VITE_PLATFORM=web|capacitor|electron
|
VITE_PLATFORM=web|capacitor|electron
|
||||||
|
|
||||||
# PWA configuration
|
# PWA configuration
|
||||||
VITE_PWA_ENABLED=true|false
|
PWA: automatically enabled for web platforms
|
||||||
VITE_DISABLE_PWA=true|false
|
|
||||||
|
|
||||||
# Build information
|
# Build information
|
||||||
VITE_GIT_HASH=<git-commit-hash>
|
VITE_GIT_HASH=<git-commit-hash>
|
||||||
@@ -396,7 +395,7 @@ xcrun devicectl list devices
|
|||||||
```bash
|
```bash
|
||||||
# Verify environment variables
|
# Verify environment variables
|
||||||
echo $VITE_PLATFORM
|
echo $VITE_PLATFORM
|
||||||
echo $VITE_PWA_ENABLED
|
echo "PWA: automatically enabled for web platforms"
|
||||||
|
|
||||||
# Check environment files
|
# Check environment files
|
||||||
ls -la .env*
|
ls -la .env*
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ npx vite --version
|
|||||||
|
|
||||||
# Check environment variables
|
# Check environment variables
|
||||||
echo $VITE_PLATFORM
|
echo $VITE_PLATFORM
|
||||||
echo $VITE_PWA_ENABLED
|
echo "PWA: automatically enabled for web platforms"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Build System Status
|
### Build System Status
|
||||||
@@ -75,8 +75,8 @@ npm run build:web:dev
|
|||||||
# Clear browser cache
|
# Clear browser cache
|
||||||
# DevTools > Application > Storage > Clear site data
|
# DevTools > Application > Storage > Clear site data
|
||||||
|
|
||||||
# Restart with PWA disabled
|
# Restart development server
|
||||||
VITE_DISABLE_PWA=true npm run build:web:dev
|
npm run build:web:dev
|
||||||
```
|
```
|
||||||
|
|
||||||
### Production Build Issues
|
### Production Build Issues
|
||||||
@@ -414,11 +414,10 @@ ls -la .env*
|
|||||||
|
|
||||||
# Set required variables
|
# Set required variables
|
||||||
export VITE_PLATFORM=web
|
export VITE_PLATFORM=web
|
||||||
export VITE_PWA_ENABLED=true
|
|
||||||
|
|
||||||
# Check in build script
|
# Check in build script
|
||||||
echo $VITE_PLATFORM
|
echo $VITE_PLATFORM
|
||||||
echo $VITE_PWA_ENABLED
|
echo "PWA: automatically enabled for web platforms"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Wrong Environment Loaded
|
#### Wrong Environment Loaded
|
||||||
|
|||||||
289
docs/pwa-build-analysis.md
Normal file
289
docs/pwa-build-analysis.md
Normal file
@@ -0,0 +1,289 @@
|
|||||||
|
# PWA Build Analysis - Web Environments
|
||||||
|
|
||||||
|
**Date**: July 15, 2025
|
||||||
|
**Author**: Matthew Raymer
|
||||||
|
**Scope**: Web builds across dev, test, and prod environments
|
||||||
|
|
||||||
|
## Executive Summary
|
||||||
|
|
||||||
|
The TimeSafari application has comprehensive PWA (Progressive Web App) support configured across all web build environments. **PWA functionality is now always enabled for web platforms**, removing the previous environment-specific toggle mechanism. The PWA features are properly integrated and provide consistent functionality across all web builds.
|
||||||
|
|
||||||
|
## PWA Configuration Overview
|
||||||
|
|
||||||
|
### Core PWA Setup
|
||||||
|
- **Plugin**: `vite-plugin-pwa` with `VitePWA` configuration
|
||||||
|
- **Service Worker**: Custom service worker with Workbox integration
|
||||||
|
- **Manifest**: Dynamic PWA manifest with environment-specific settings
|
||||||
|
- **Registration**: Auto-update registration type
|
||||||
|
- **Status**: ✅ **Always enabled for web platforms**
|
||||||
|
|
||||||
|
### Environment-Specific PWA Status
|
||||||
|
|
||||||
|
| Environment | PWA Status | Dev Options | Service Worker | Manifest | Install Prompt |
|
||||||
|
|-------------|------------|-------------|----------------|----------|----------------|
|
||||||
|
| **Development** | ✅ Always Enabled | ✅ `enabled: true` | ✅ Active | ✅ Generated | ✅ Available |
|
||||||
|
| **Test** | ✅ Always Enabled | ✅ `enabled: true` | ✅ Active | ✅ Generated | ✅ Available |
|
||||||
|
| **Production** | ✅ Always Enabled | ✅ `enabled: true` | ✅ Active | ✅ Generated | ✅ Available |
|
||||||
|
|
||||||
|
## Detailed Environment Analysis
|
||||||
|
|
||||||
|
### Development Environment (`.env.development`)
|
||||||
|
|
||||||
|
**Configuration**:
|
||||||
|
```bash
|
||||||
|
VITE_DEFAULT_ENDORSER_API_SERVER=http://127.0.0.1:3000
|
||||||
|
```
|
||||||
|
|
||||||
|
**PWA Features**:
|
||||||
|
- ✅ **Full PWA Support**: Always enabled for development testing
|
||||||
|
- ✅ **Service Worker**: Active with development optimizations
|
||||||
|
- ✅ **Manifest**: Generated with development settings
|
||||||
|
- ✅ **Install Prompt**: Available for testing PWA installation
|
||||||
|
- ✅ **Dev Options**: `enabled: true` for consistent testing
|
||||||
|
|
||||||
|
**Build Command**:
|
||||||
|
```bash
|
||||||
|
npm run build:web:dev
|
||||||
|
# or
|
||||||
|
./scripts/build-web.sh --dev
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test Environment (`.env.test`)
|
||||||
|
|
||||||
|
**Configuration**:
|
||||||
|
```bash
|
||||||
|
VITE_APP_SERVER=https://test.timesafari.app
|
||||||
|
VITE_DEFAULT_ENDORSER_API_SERVER=https://test-api.endorser.ch
|
||||||
|
```
|
||||||
|
|
||||||
|
**PWA Features**:
|
||||||
|
- ✅ **Full PWA Support**: Always enabled for test environment
|
||||||
|
- ✅ **Service Worker**: Active with test optimizations
|
||||||
|
- ✅ **Manifest**: Generated and fully utilized
|
||||||
|
- ✅ **Install Prompt**: Available for test installations
|
||||||
|
- ✅ **Dev Options**: Enabled for debugging
|
||||||
|
|
||||||
|
**Build Command**:
|
||||||
|
```bash
|
||||||
|
npm run build:web:test
|
||||||
|
# or
|
||||||
|
./scripts/build-web.sh --test
|
||||||
|
```
|
||||||
|
|
||||||
|
### Production Environment (`.env.production`)
|
||||||
|
|
||||||
|
**Configuration**:
|
||||||
|
```bash
|
||||||
|
VITE_APP_SERVER=https://timesafari.app
|
||||||
|
VITE_DEFAULT_ENDORSER_API_SERVER=https://api.endorser.ch
|
||||||
|
```
|
||||||
|
|
||||||
|
**PWA Features**:
|
||||||
|
- ✅ **Full PWA Support**: Always enabled for production users
|
||||||
|
- ✅ **Service Worker**: Active with production optimizations
|
||||||
|
- ✅ **Manifest**: Generated with production settings
|
||||||
|
- ✅ **Install Prompt**: Available for user installations
|
||||||
|
- ✅ **Dev Options**: Enabled for production debugging
|
||||||
|
|
||||||
|
**Build Command**:
|
||||||
|
```bash
|
||||||
|
npm run build:web:prod
|
||||||
|
# or
|
||||||
|
./scripts/build-web.sh --prod
|
||||||
|
```
|
||||||
|
|
||||||
|
## Technical Implementation
|
||||||
|
|
||||||
|
### Vite Configuration (`vite.config.web.mts`)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
VitePWA({
|
||||||
|
registerType: 'autoUpdate',
|
||||||
|
manifest: appConfig.pwaConfig?.manifest,
|
||||||
|
// Enable PWA in all web environments for consistent testing
|
||||||
|
devOptions: {
|
||||||
|
enabled: true, // ✅ Enable in all environments
|
||||||
|
type: 'module'
|
||||||
|
},
|
||||||
|
workbox: {
|
||||||
|
cleanupOutdatedCaches: true,
|
||||||
|
skipWaiting: true,
|
||||||
|
clientsClaim: true,
|
||||||
|
sourcemap: mode !== 'production',
|
||||||
|
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024, // 10MB
|
||||||
|
// Environment-specific caching strategies
|
||||||
|
runtimeCaching: mode === 'production' ? [
|
||||||
|
{
|
||||||
|
urlPattern: /^https:\/\/api\./,
|
||||||
|
handler: 'NetworkFirst',
|
||||||
|
options: {
|
||||||
|
cacheName: 'api-cache',
|
||||||
|
expiration: {
|
||||||
|
maxEntries: 100,
|
||||||
|
maxAgeSeconds: 60 * 60 * 24 // 24 hours
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
] : []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### PWA Manifest Configuration (`vite.config.utils.mts`)
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
manifest: {
|
||||||
|
name: appName,
|
||||||
|
short_name: appName,
|
||||||
|
theme_color: "#4a90e2",
|
||||||
|
background_color: "#ffffff",
|
||||||
|
icons: [
|
||||||
|
{
|
||||||
|
src: "./img/icons/android-chrome-192x192.png",
|
||||||
|
sizes: "192x192",
|
||||||
|
type: "image/png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: "./img/icons/android-chrome-512x512.png",
|
||||||
|
sizes: "512x512",
|
||||||
|
type: "image/png",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: "./img/icons/android-chrome-maskable-192x192.png",
|
||||||
|
sizes: "192x192",
|
||||||
|
type: "image/png",
|
||||||
|
purpose: "maskable",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: "./img/icons/android-chrome-maskable-512x512.png",
|
||||||
|
sizes: "512x512",
|
||||||
|
type: "image/png",
|
||||||
|
purpose: "maskable",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
share_target: {
|
||||||
|
action: "/share-target",
|
||||||
|
method: "POST",
|
||||||
|
enctype: "multipart/form-data",
|
||||||
|
params: {
|
||||||
|
files: [
|
||||||
|
{
|
||||||
|
name: "photo",
|
||||||
|
accept: ["image/*"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Build Process Analysis
|
||||||
|
|
||||||
|
### Environment Detection
|
||||||
|
The build system automatically detects the environment and applies appropriate PWA settings:
|
||||||
|
|
||||||
|
1. **Environment Files**: `.env.development`, `.env.test`, `.env.production`
|
||||||
|
2. **Vite Mode**: Passed via `--mode` parameter
|
||||||
|
3. **PWA Status**: Always enabled for web platforms (no longer environment-dependent)
|
||||||
|
4. **Dev Options**: Always enabled for consistent testing
|
||||||
|
|
||||||
|
### Build Script Integration
|
||||||
|
The `build-web.sh` script properly handles environment setup:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Environment-specific configuration
|
||||||
|
case $BUILD_MODE in
|
||||||
|
"production")
|
||||||
|
export NODE_ENV="production"
|
||||||
|
;;
|
||||||
|
"test")
|
||||||
|
export NODE_ENV="test"
|
||||||
|
;;
|
||||||
|
"development"|*)
|
||||||
|
export NODE_ENV="development"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Load environment-specific .env file
|
||||||
|
local env_file=".env.$BUILD_MODE"
|
||||||
|
if [ -f "$env_file" ]; then
|
||||||
|
load_env_file "$env_file"
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
## PWA Features by Environment
|
||||||
|
|
||||||
|
### Development Features
|
||||||
|
- **Hot Reload**: Service worker updates automatically
|
||||||
|
- **Debug Mode**: Full PWA functionality for testing
|
||||||
|
- **Local Testing**: Install prompt available
|
||||||
|
- **Development Server**: PWA features work on localhost
|
||||||
|
|
||||||
|
### Test Features
|
||||||
|
- **Full PWA**: Complete PWA functionality for testing
|
||||||
|
- **Service Worker**: Active with test optimizations
|
||||||
|
- **Manifest**: Generated and fully utilized
|
||||||
|
- **Install Prompt**: Available for test installations
|
||||||
|
|
||||||
|
### Production Features
|
||||||
|
- **Full PWA**: Complete Progressive Web App functionality
|
||||||
|
- **Service Worker**: Production-optimized caching
|
||||||
|
- **Install Prompt**: Available for user installations
|
||||||
|
- **API Caching**: Network-first strategy for API calls
|
||||||
|
- **Offline Support**: Cached resources for offline use
|
||||||
|
|
||||||
|
## Recent Changes
|
||||||
|
|
||||||
|
### PWA Always Enabled
|
||||||
|
- **Removed**: `VITE_PWA_ENABLED` environment variable (no longer used)
|
||||||
|
- **Updated**: Service worker registration to always run
|
||||||
|
- **Simplified**: PWA component logic
|
||||||
|
- **Consistent**: PWA behavior across all environments
|
||||||
|
|
||||||
|
### Updated Files
|
||||||
|
- `vite.config.common.mts`: Removed PWA toggle logic
|
||||||
|
- `src/registerServiceWorker.ts`: Removed (VitePWA handles registration automatically)
|
||||||
|
- `src/main.web.ts`: Always import service worker
|
||||||
|
- `src/components/PWAInstallPrompt.vue`: Removed PWA check
|
||||||
|
- `src/services/platforms/WebPlatformService.ts`: Always return true for PWA
|
||||||
|
- `scripts/common.sh`: Removed VITE_PWA_ENABLED setting
|
||||||
|
- Environment files: Removed VITE_PWA_ENABLED variables
|
||||||
|
- Vite configs: Removed VITE_PWA_ENABLED and VITE_DISABLE_PWA assignments
|
||||||
|
|
||||||
|
## Recommendations
|
||||||
|
|
||||||
|
### Current State Assessment
|
||||||
|
✅ **Excellent**: PWA is properly configured and always enabled for web
|
||||||
|
✅ **Consistent**: Same PWA functionality across all environments
|
||||||
|
✅ **Simplified**: Removed unnecessary conditional logic
|
||||||
|
✅ **Reliable**: No environment-specific PWA toggles
|
||||||
|
|
||||||
|
### Potential Improvements
|
||||||
|
1. **Test Environment**: Consider PWA-specific test scenarios
|
||||||
|
2. **Caching Strategy**: Review API caching for all environments
|
||||||
|
3. **Manifest Icons**: Ensure all icon sizes are optimized
|
||||||
|
4. **Service Worker**: Add more sophisticated offline strategies
|
||||||
|
|
||||||
|
### Monitoring Considerations
|
||||||
|
1. **Installation Metrics**: Track PWA installations across environments
|
||||||
|
2. **Service Worker Performance**: Monitor cache hit rates
|
||||||
|
3. **Offline Usage**: Analyze offline functionality usage
|
||||||
|
4. **Update Success**: Monitor service worker update success rates
|
||||||
|
|
||||||
|
## Conclusion
|
||||||
|
|
||||||
|
The TimeSafari web build system now has **simplified and consistent PWA support** across all environments. PWA functionality is controlled entirely through build-time configuration:
|
||||||
|
|
||||||
|
- **Web platforms**: PWA is always enabled via `vite.config.web.mts` plugin inclusion
|
||||||
|
- **Native platforms**: PWA is disabled via build-time package exclusion in `vite.config.common.mts`
|
||||||
|
- **No environment variables**: Removed redundant `VITE_PWA_ENABLED` and `VITE_DISABLE_PWA` variables
|
||||||
|
|
||||||
|
This approach provides a more reliable and predictable user experience with cleaner configuration.
|
||||||
|
|
||||||
|
The implementation follows best practices with proper environment detection, consistent PWA enabling, and comprehensive service worker configuration. The PWA features are well-integrated into the build process and provide a solid foundation for progressive web app functionality across all web environments.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Analysis Date**: July 15, 2025
|
||||||
|
**Status**: ✅ PWA always enabled for web platforms
|
||||||
|
**Next Review**: After major PWA feature updates
|
||||||
@@ -92,8 +92,8 @@ rm -rf dist* || log_warn "No previous builds to clean"
|
|||||||
# Set environment variables for the build
|
# Set environment variables for the build
|
||||||
log_info "Configuring build environment..."
|
log_info "Configuring build environment..."
|
||||||
export VITE_PLATFORM=electron
|
export VITE_PLATFORM=electron
|
||||||
export VITE_PWA_ENABLED=false
|
|
||||||
export VITE_DISABLE_PWA=true
|
|
||||||
export DEBUG_MIGRATIONS=0
|
export DEBUG_MIGRATIONS=0
|
||||||
|
|
||||||
# Ensure TypeScript is installed
|
# Ensure TypeScript is installed
|
||||||
|
|||||||
@@ -178,27 +178,19 @@ setup_build_env() {
|
|||||||
case $build_type in
|
case $build_type in
|
||||||
"capacitor")
|
"capacitor")
|
||||||
export VITE_PLATFORM=capacitor
|
export VITE_PLATFORM=capacitor
|
||||||
export VITE_PWA_ENABLED=false
|
|
||||||
export VITE_DISABLE_PWA=true
|
|
||||||
export DEBUG_MIGRATIONS=0
|
export DEBUG_MIGRATIONS=0
|
||||||
;;
|
;;
|
||||||
"electron")
|
"electron")
|
||||||
export VITE_PLATFORM=electron
|
export VITE_PLATFORM=electron
|
||||||
export VITE_PWA_ENABLED=false
|
|
||||||
export VITE_DISABLE_PWA=true
|
|
||||||
export DEBUG_MIGRATIONS=0
|
export DEBUG_MIGRATIONS=0
|
||||||
;;
|
;;
|
||||||
"web")
|
"web")
|
||||||
export VITE_PLATFORM=web
|
export VITE_PLATFORM=web
|
||||||
export VITE_PWA_ENABLED=true
|
|
||||||
export VITE_DISABLE_PWA=false
|
|
||||||
export DEBUG_MIGRATIONS=0
|
export DEBUG_MIGRATIONS=0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
log_warn "Unknown build type: $build_type, using default environment"
|
log_warn "Unknown build type: $build_type, using default environment"
|
||||||
export VITE_PLATFORM=web
|
export VITE_PLATFORM=web
|
||||||
export VITE_PWA_ENABLED=true
|
|
||||||
export VITE_DISABLE_PWA=false
|
|
||||||
export DEBUG_MIGRATIONS=0
|
export DEBUG_MIGRATIONS=0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -206,8 +198,6 @@ setup_build_env() {
|
|||||||
# Log environment setup
|
# Log environment setup
|
||||||
log_debug "Environment variables set:"
|
log_debug "Environment variables set:"
|
||||||
log_debug " VITE_PLATFORM=$VITE_PLATFORM"
|
log_debug " VITE_PLATFORM=$VITE_PLATFORM"
|
||||||
log_debug " VITE_PWA_ENABLED=$VITE_PWA_ENABLED"
|
|
||||||
log_debug " VITE_DISABLE_PWA=$VITE_DISABLE_PWA"
|
|
||||||
log_debug " DEBUG_MIGRATIONS=$DEBUG_MIGRATIONS"
|
log_debug " DEBUG_MIGRATIONS=$DEBUG_MIGRATIONS"
|
||||||
if [ -n "$NODE_ENV" ]; then
|
if [ -n "$NODE_ENV" ]; then
|
||||||
log_debug " NODE_ENV=$NODE_ENV"
|
log_debug " NODE_ENV=$NODE_ENV"
|
||||||
|
|||||||
@@ -79,12 +79,6 @@ export default class PWAInstallPrompt extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setupInstallPrompt() {
|
private setupInstallPrompt() {
|
||||||
// Only show install prompt if PWA is enabled
|
|
||||||
if (process.env.VITE_PWA_ENABLED !== "true") {
|
|
||||||
logger.debug("[PWA] Install prompt disabled - PWA not enabled");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if already installed
|
// Check if already installed
|
||||||
if (this.isPWAInstalled()) {
|
if (this.isPWAInstalled()) {
|
||||||
logger.debug("[PWA] Install prompt disabled - PWA already installed");
|
logger.debug("[PWA] Install prompt disabled - PWA already installed");
|
||||||
@@ -95,9 +89,6 @@ export default class PWAInstallPrompt extends Vue {
|
|||||||
window.addEventListener('beforeinstallprompt', (e) => {
|
window.addEventListener('beforeinstallprompt', (e) => {
|
||||||
logger.debug("[PWA] beforeinstallprompt event fired");
|
logger.debug("[PWA] beforeinstallprompt event fired");
|
||||||
|
|
||||||
// Prevent the mini-infobar from appearing on mobile
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
// Stash the event so it can be triggered later
|
// Stash the event so it can be triggered later
|
||||||
this.deferredPrompt = e as BeforeInstallPromptEvent;
|
this.deferredPrompt = e as BeforeInstallPromptEvent;
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import {
|
|||||||
faComment,
|
faComment,
|
||||||
faCopy,
|
faCopy,
|
||||||
faDollar,
|
faDollar,
|
||||||
|
faDownload,
|
||||||
faEllipsis,
|
faEllipsis,
|
||||||
faEllipsisVertical,
|
faEllipsisVertical,
|
||||||
faEnvelopeOpenText,
|
faEnvelopeOpenText,
|
||||||
@@ -121,6 +122,7 @@ library.add(
|
|||||||
faComment,
|
faComment,
|
||||||
faCopy,
|
faCopy,
|
||||||
faDollar,
|
faDollar,
|
||||||
|
faDownload,
|
||||||
faEllipsis,
|
faEllipsis,
|
||||||
faEllipsisVertical,
|
faEllipsisVertical,
|
||||||
faEnvelopeOpenText,
|
faEnvelopeOpenText,
|
||||||
|
|||||||
@@ -2,12 +2,8 @@ import { initializeApp } from "./main.common";
|
|||||||
import { logger } from "./utils/logger";
|
import { logger } from "./utils/logger";
|
||||||
|
|
||||||
const platform = process.env.VITE_PLATFORM;
|
const platform = process.env.VITE_PLATFORM;
|
||||||
const pwa_enabled = process.env.VITE_PWA_ENABLED === "true";
|
|
||||||
|
|
||||||
// Only import service worker for web builds
|
// PWA service worker is automatically registered by VitePWA plugin
|
||||||
if (pwa_enabled) {
|
|
||||||
import("./registerServiceWorker"); // Web PWA support
|
|
||||||
}
|
|
||||||
|
|
||||||
const app = initializeApp();
|
const app = initializeApp();
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
/* eslint-disable no-console */
|
|
||||||
|
|
||||||
import { register } from "register-service-worker";
|
|
||||||
|
|
||||||
// Register service worker if PWA is enabled
|
|
||||||
// Enable in all environments for consistent testing and functionality
|
|
||||||
if (process.env.VITE_PWA_ENABLED === "true") {
|
|
||||||
register(`${process.env.BASE_URL}sw.js`, {
|
|
||||||
ready() {
|
|
||||||
console.log("Service worker is active.");
|
|
||||||
},
|
|
||||||
registered() {
|
|
||||||
console.log("Service worker has been registered.");
|
|
||||||
},
|
|
||||||
cached() {
|
|
||||||
console.log("Content has been cached for offline use.");
|
|
||||||
},
|
|
||||||
updatefound() {
|
|
||||||
console.log("New content is downloading.");
|
|
||||||
},
|
|
||||||
updated() {
|
|
||||||
console.log("New content is available; please refresh.");
|
|
||||||
},
|
|
||||||
offline() {
|
|
||||||
console.log(
|
|
||||||
"No internet connection found. App is running in offline mode.",
|
|
||||||
);
|
|
||||||
},
|
|
||||||
error(error) {
|
|
||||||
console.error("Error during service worker registration:", error);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
`Service worker registration skipped - PWA not enabled (VITE_PWA_ENABLED=${process.env.VITE_PWA_ENABLED})`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -647,13 +647,13 @@ export class WebPlatformService implements PlatformService {
|
|||||||
|
|
||||||
// --- PWA/Web-only methods ---
|
// --- PWA/Web-only methods ---
|
||||||
public registerServiceWorker(): void {
|
public registerServiceWorker(): void {
|
||||||
if (this.isPWAEnabled) {
|
// PWA service worker is automatically registered by VitePWA plugin
|
||||||
import("@/registerServiceWorker");
|
// No manual registration needed
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get isPWAEnabled(): boolean {
|
public get isPWAEnabled(): boolean {
|
||||||
return process.env.VITE_PWA_ENABLED === "true";
|
// PWA is always enabled for web platform
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,17 +17,8 @@ export async function createBuildConfig(platform: string): Promise<UserConfig> {
|
|||||||
const isElectron = platform === "electron";
|
const isElectron = platform === "electron";
|
||||||
const isNative = isCapacitor || isElectron;
|
const isNative = isCapacitor || isElectron;
|
||||||
|
|
||||||
// Set platform and configure PWA based on environment or platform
|
// Set platform - PWA is always enabled for web platforms
|
||||||
process.env.VITE_PLATFORM = platform;
|
process.env.VITE_PLATFORM = platform;
|
||||||
|
|
||||||
// Use .env file value if set, otherwise default based on platform
|
|
||||||
if (process.env.VITE_PWA_ENABLED === undefined) {
|
|
||||||
process.env.VITE_PWA_ENABLED = isNative ? 'false' : 'true';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNative) {
|
|
||||||
process.env.VITE_PWA_ENABLED = 'false';
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
base: "/",
|
base: "/",
|
||||||
@@ -63,7 +54,7 @@ export async function createBuildConfig(platform: string): Promise<UserConfig> {
|
|||||||
define: {
|
define: {
|
||||||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
||||||
'process.env.VITE_PLATFORM': JSON.stringify(platform),
|
'process.env.VITE_PLATFORM': JSON.stringify(platform),
|
||||||
'process.env.VITE_PWA_ENABLED': JSON.stringify(!isNative),
|
// PWA is always enabled for web platforms
|
||||||
__dirname: JSON.stringify(process.cwd()),
|
__dirname: JSON.stringify(process.cwd()),
|
||||||
__IS_MOBILE__: JSON.stringify(isCapacitor),
|
__IS_MOBILE__: JSON.stringify(isCapacitor),
|
||||||
__IS_ELECTRON__: JSON.stringify(isElectron),
|
__IS_ELECTRON__: JSON.stringify(isElectron),
|
||||||
|
|||||||
@@ -20,8 +20,7 @@
|
|||||||
*
|
*
|
||||||
* Environment Variables:
|
* Environment Variables:
|
||||||
* - VITE_PLATFORM: Set to "electron"
|
* - VITE_PLATFORM: Set to "electron"
|
||||||
* - VITE_PWA_ENABLED: Disabled for desktop
|
* - PWA: Disabled for desktop (via build exclusion)
|
||||||
* - VITE_DISABLE_PWA: Enabled for desktop
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
@@ -140,8 +139,8 @@ export default defineConfig(async () => {
|
|||||||
define: {
|
define: {
|
||||||
...baseConfig.define,
|
...baseConfig.define,
|
||||||
'process.env.VITE_PLATFORM': JSON.stringify('electron'),
|
'process.env.VITE_PLATFORM': JSON.stringify('electron'),
|
||||||
'process.env.VITE_PWA_ENABLED': JSON.stringify(false),
|
|
||||||
'process.env.VITE_DISABLE_PWA': JSON.stringify(true),
|
|
||||||
// Electron-specific flags
|
// Electron-specific flags
|
||||||
'__ELECTRON__': JSON.stringify(true),
|
'__ELECTRON__': JSON.stringify(true),
|
||||||
'__IS_DESKTOP__': JSON.stringify(true),
|
'__IS_DESKTOP__': JSON.stringify(true),
|
||||||
|
|||||||
@@ -24,14 +24,8 @@ export async function createOptimizedBuildConfig(mode: string): Promise<UserConf
|
|||||||
const isElectron = mode === "electron";
|
const isElectron = mode === "electron";
|
||||||
const isNative = isCapacitor || isElectron;
|
const isNative = isCapacitor || isElectron;
|
||||||
|
|
||||||
// Set platform and disable PWA for native platforms
|
// Set platform - PWA is always enabled for web platforms
|
||||||
process.env.VITE_PLATFORM = mode;
|
process.env.VITE_PLATFORM = mode;
|
||||||
process.env.VITE_PWA_ENABLED = isNative ? 'false' : 'true';
|
|
||||||
process.env.VITE_DISABLE_PWA = isNative ? 'true' : 'false';
|
|
||||||
|
|
||||||
if (isNative) {
|
|
||||||
process.env.VITE_PWA_ENABLED = 'false';
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
base: "/",
|
base: "/",
|
||||||
@@ -93,8 +87,8 @@ export async function createOptimizedBuildConfig(mode: string): Promise<UserConf
|
|||||||
define: {
|
define: {
|
||||||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
||||||
'process.env.VITE_PLATFORM': JSON.stringify(mode),
|
'process.env.VITE_PLATFORM': JSON.stringify(mode),
|
||||||
'process.env.VITE_PWA_ENABLED': JSON.stringify(!isNative),
|
|
||||||
'process.env.VITE_DISABLE_PWA': JSON.stringify(isNative),
|
|
||||||
__dirname: JSON.stringify(process.cwd()),
|
__dirname: JSON.stringify(process.cwd()),
|
||||||
__IS_MOBILE__: JSON.stringify(isCapacitor),
|
__IS_MOBILE__: JSON.stringify(isCapacitor),
|
||||||
__IS_ELECTRON__: JSON.stringify(isElectron),
|
__IS_ELECTRON__: JSON.stringify(isElectron),
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ export default defineConfig(async ({ mode }) => {
|
|||||||
// Enable PWA in all web environments for consistent testing
|
// Enable PWA in all web environments for consistent testing
|
||||||
devOptions: {
|
devOptions: {
|
||||||
enabled: true, // ✅ Enable in all environments
|
enabled: true, // ✅ Enable in all environments
|
||||||
type: 'module'
|
type: 'classic'
|
||||||
},
|
},
|
||||||
workbox: {
|
workbox: {
|
||||||
cleanupOutdatedCaches: true,
|
cleanupOutdatedCaches: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user