Browse Source

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.
web-serve-fix
Matthew Raymer 2 weeks ago
parent
commit
6b0326b582
  1. 2
      .cursor/rules/architectural_decision_record.mdc
  2. 1
      .env.development
  3. 1
      .env.production
  4. 1
      .env.test
  5. 2
      dev-dist/sw.js
  6. 2
      dev-dist/sw.js.map
  7. 2
      doc/qr-code-implementation-guide.md
  8. 10
      docker/README.md
  9. 18
      docker/run.sh
  10. 7
      docs/build-systems-overview.md
  11. 9
      docs/build-troubleshooting.md
  12. 289
      docs/pwa-build-analysis.md
  13. 4
      experiment.sh
  14. 10
      scripts/common.sh
  15. 9
      src/components/PWAInstallPrompt.vue
  16. 2
      src/libs/fontawesome.ts
  17. 6
      src/main.web.ts
  18. 37
      src/registerServiceWorker.ts
  19. 8
      src/services/platforms/WebPlatformService.ts
  20. 13
      vite.config.common.mts
  21. 7
      vite.config.electron.mts
  22. 12
      vite.config.optimized.mts
  23. 2
      vite.config.web.mts

2
.cursor/rules/architectural_decision_record.mdc

@ -149,7 +149,7 @@ export function createBuildConfig(mode: string) {
return {
define: {
'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),
__USE_QR_READER__: JSON.stringify(!isCapacitor)
}

1
.env.development

@ -1,2 +1 @@
VITE_DEFAULT_ENDORSER_API_SERVER=http://127.0.0.1:3000
VITE_PWA_ENABLED=true

1
.env.production

@ -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_PARTNER_API_SERVER=https://partner-api.endorser.ch
VITE_DEFAULT_PUSH_SERVER=https://timesafari.app
VITE_PWA_ENABLED=true

1
.env.test

@ -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_PUSH_SERVER=https://test.timesafari.app
VITE_PASSKEYS_ENABLED=true
VITE_PWA_ENABLED=false

2
dev-dist/sw.js

@ -82,7 +82,7 @@ define(['./workbox-54d0af47'], (function (workbox) { 'use strict';
"revision": "3ca0b8505b4bec776b69afdba2768812"
}, {
"url": "index.html",
"revision": "0.qptlo5ufc6o"
"revision": "0.6n0ha79iivo"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {

2
dev-dist/sw.js.map

File diff suppressed because one or more lines are too long

2
doc/qr-code-implementation-guide.md

@ -168,7 +168,7 @@ export async function createBuildConfig(mode: string) {
return defineConfig({
define: {
'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),
__USE_QR_READER__: JSON.stringify(!isCapacitor)
},

10
docker/README.md

@ -72,7 +72,7 @@ docker build --build-arg BUILD_MODE=development -t timesafari:dev .
docker build \
--build-arg BUILD_MODE=staging \
--build-arg NODE_ENV=staging \
--build-arg VITE_PWA_ENABLED=true \
-t timesafari:custom .
```
@ -103,8 +103,7 @@ The Dockerfile supports these build arguments:
| `BUILD_MODE` | `production` | Build mode: development, staging, or production |
| `NODE_ENV` | `production` | Node.js environment |
| `VITE_PLATFORM` | `web` | Vite platform type |
| `VITE_PWA_ENABLED` | `true` | Enable PWA features |
| `VITE_DISABLE_PWA` | `false` | Disable PWA features |
| PWA | `enabled` | Automatically enabled for web platforms |
### Environment Variables
@ -115,8 +114,7 @@ Docker Compose supports these environment variables:
| `BUILD_MODE` | `production` | Build mode |
| `NODE_ENV` | `production` | Node environment |
| `VITE_PLATFORM` | `web` | Vite platform |
| `VITE_PWA_ENABLED` | `true` | Enable PWA |
| `VITE_DISABLE_PWA` | `false` | Disable PWA |
| PWA | `enabled` | Automatically enabled for web platforms |
| `DEV_PORT` | `5173` | Development port |
| `STAGING_PORT` | `8080` | Staging port |
| `PROD_PORT` | `80` | Production port |
@ -214,7 +212,7 @@ BUILD_MODE=staging NODE_ENV=staging ./docker/run.sh custom
docker build \
--build-arg BUILD_MODE=staging \
--build-arg NODE_ENV=staging \
--build-arg VITE_PWA_ENABLED=false \
-t timesafari:staging-no-pwa .
# Run with custom configuration

18
docker/run.sh

@ -13,8 +13,7 @@
# BUILD_MODE: development, staging, or production
# NODE_ENV: node environment
# VITE_PLATFORM: vite platform
# VITE_PWA_ENABLED: enable PWA
# VITE_DISABLE_PWA: disable PWA
# PWA: automatically enabled for web platforms
# PORT: port to expose
# ENV_FILE: environment file to use
@ -72,8 +71,7 @@ show_usage() {
echo " BUILD_MODE: development, staging, or production"
echo " NODE_ENV: node environment"
echo " VITE_PLATFORM: vite platform"
echo " VITE_PWA_ENABLED: enable PWA"
echo " VITE_DISABLE_PWA: disable PWA"
echo " PWA: automatically enabled for web platforms"
echo " PORT: port to expose"
echo " ENV_FILE: environment file to use"
}
@ -88,8 +86,7 @@ show_build_args() {
echo " BUILD_MODE: development"
echo " NODE_ENV: development"
echo " VITE_PLATFORM: web"
echo " VITE_PWA_ENABLED: true"
echo " VITE_DISABLE_PWA: false"
echo " PWA: enabled (web platform)"
echo " Target: development"
echo " Port: 5173"
;;
@ -97,8 +94,7 @@ show_build_args() {
echo " BUILD_MODE: staging"
echo " NODE_ENV: staging"
echo " VITE_PLATFORM: web"
echo " VITE_PWA_ENABLED: true"
echo " VITE_DISABLE_PWA: false"
echo " PWA: enabled (web platform)"
echo " Target: staging"
echo " Port: 80 (mapped to 8080)"
;;
@ -106,8 +102,7 @@ show_build_args() {
echo " BUILD_MODE: production"
echo " NODE_ENV: production"
echo " VITE_PLATFORM: web"
echo " VITE_PWA_ENABLED: true"
echo " VITE_DISABLE_PWA: false"
echo " PWA: enabled (web platform)"
echo " Target: production"
echo " Port: 80"
;;
@ -115,8 +110,7 @@ show_build_args() {
echo " BUILD_MODE: \${BUILD_MODE:-production}"
echo " NODE_ENV: \${NODE_ENV:-production}"
echo " VITE_PLATFORM: \${VITE_PLATFORM:-web}"
echo " VITE_PWA_ENABLED: \${VITE_PWA_ENABLED:-true}"
echo " VITE_DISABLE_PWA: \${VITE_DISABLE_PWA:-false}"
echo " PWA: enabled for web platforms"
echo " Target: \${BUILD_TARGET:-production}"
echo " Port: \${CUSTOM_PORT:-8080}:\${CUSTOM_INTERNAL_PORT:-80}"
;;

7
docs/build-systems-overview.md

@ -38,7 +38,7 @@ All build scripts follow a consistent pattern:
```bash
# Set platform-specific environment variables
VITE_PLATFORM=<platform>
VITE_PWA_ENABLED=<true/false>
PWA: automatically enabled for web platforms
VITE_GIT_HASH=<git-commit-hash>
```
@ -212,8 +212,7 @@ All build systems use consistent environment variable patterns:
VITE_PLATFORM=web|capacitor|electron
# PWA configuration
VITE_PWA_ENABLED=true|false
VITE_DISABLE_PWA=true|false
PWA: automatically enabled for web platforms
# Build information
VITE_GIT_HASH=<git-commit-hash>
@ -396,7 +395,7 @@ xcrun devicectl list devices
```bash
# Verify environment variables
echo $VITE_PLATFORM
echo $VITE_PWA_ENABLED
echo "PWA: automatically enabled for web platforms"
# Check environment files
ls -la .env*

9
docs/build-troubleshooting.md

@ -22,7 +22,7 @@ npx vite --version
# Check environment variables
echo $VITE_PLATFORM
echo $VITE_PWA_ENABLED
echo "PWA: automatically enabled for web platforms"
```
### Build System Status
@ -75,8 +75,8 @@ npm run build:web:dev
# Clear browser cache
# DevTools > Application > Storage > Clear site data
# Restart with PWA disabled
VITE_DISABLE_PWA=true npm run build:web:dev
# Restart development server
npm run build:web:dev
```
### Production Build Issues
@ -414,11 +414,10 @@ ls -la .env*
# Set required variables
export VITE_PLATFORM=web
export VITE_PWA_ENABLED=true
# Check in build script
echo $VITE_PLATFORM
echo $VITE_PWA_ENABLED
echo "PWA: automatically enabled for web platforms"
```
#### Wrong Environment Loaded

289
docs/pwa-build-analysis.md

@ -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

4
experiment.sh

@ -92,8 +92,8 @@ rm -rf dist* || log_warn "No previous builds to clean"
# Set environment variables for the build
log_info "Configuring build environment..."
export VITE_PLATFORM=electron
export VITE_PWA_ENABLED=false
export VITE_DISABLE_PWA=true
export DEBUG_MIGRATIONS=0
# Ensure TypeScript is installed

10
scripts/common.sh

@ -178,27 +178,19 @@ setup_build_env() {
case $build_type in
"capacitor")
export VITE_PLATFORM=capacitor
export VITE_PWA_ENABLED=false
export VITE_DISABLE_PWA=true
export DEBUG_MIGRATIONS=0
;;
"electron")
export VITE_PLATFORM=electron
export VITE_PWA_ENABLED=false
export VITE_DISABLE_PWA=true
export DEBUG_MIGRATIONS=0
;;
"web")
export VITE_PLATFORM=web
export VITE_PWA_ENABLED=true
export VITE_DISABLE_PWA=false
export DEBUG_MIGRATIONS=0
;;
*)
log_warn "Unknown build type: $build_type, using default environment"
export VITE_PLATFORM=web
export VITE_PWA_ENABLED=true
export VITE_DISABLE_PWA=false
export DEBUG_MIGRATIONS=0
;;
esac
@ -206,8 +198,6 @@ setup_build_env() {
# Log environment setup
log_debug "Environment variables set:"
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"
if [ -n "$NODE_ENV" ]; then
log_debug " NODE_ENV=$NODE_ENV"

9
src/components/PWAInstallPrompt.vue

@ -79,12 +79,6 @@ export default class PWAInstallPrompt extends Vue {
}
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
if (this.isPWAInstalled()) {
logger.debug("[PWA] Install prompt disabled - PWA already installed");
@ -95,9 +89,6 @@ export default class PWAInstallPrompt extends Vue {
window.addEventListener('beforeinstallprompt', (e) => {
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
this.deferredPrompt = e as BeforeInstallPromptEvent;

2
src/libs/fontawesome.ts

@ -36,6 +36,7 @@ import {
faComment,
faCopy,
faDollar,
faDownload,
faEllipsis,
faEllipsisVertical,
faEnvelopeOpenText,
@ -121,6 +122,7 @@ library.add(
faComment,
faCopy,
faDollar,
faDownload,
faEllipsis,
faEllipsisVertical,
faEnvelopeOpenText,

6
src/main.web.ts

@ -2,12 +2,8 @@ import { initializeApp } from "./main.common";
import { logger } from "./utils/logger";
const platform = process.env.VITE_PLATFORM;
const pwa_enabled = process.env.VITE_PWA_ENABLED === "true";
// Only import service worker for web builds
if (pwa_enabled) {
import("./registerServiceWorker"); // Web PWA support
}
// PWA service worker is automatically registered by VitePWA plugin
const app = initializeApp();

37
src/registerServiceWorker.ts

@ -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})`,
);
}

8
src/services/platforms/WebPlatformService.ts

@ -647,13 +647,13 @@ export class WebPlatformService implements PlatformService {
// --- PWA/Web-only methods ---
public registerServiceWorker(): void {
if (this.isPWAEnabled) {
import("@/registerServiceWorker");
}
// PWA service worker is automatically registered by VitePWA plugin
// No manual registration needed
}
public get isPWAEnabled(): boolean {
return process.env.VITE_PWA_ENABLED === "true";
// PWA is always enabled for web platform
return true;
}
/**

13
vite.config.common.mts

@ -17,18 +17,9 @@ export async function createBuildConfig(platform: string): Promise<UserConfig> {
const isElectron = platform === "electron";
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;
// 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 {
base: "/",
plugins: [vue()],
@ -63,7 +54,7 @@ export async function createBuildConfig(platform: string): Promise<UserConfig> {
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'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()),
__IS_MOBILE__: JSON.stringify(isCapacitor),
__IS_ELECTRON__: JSON.stringify(isElectron),

7
vite.config.electron.mts

@ -20,8 +20,7 @@
*
* Environment Variables:
* - VITE_PLATFORM: Set to "electron"
* - VITE_PWA_ENABLED: Disabled for desktop
* - VITE_DISABLE_PWA: Enabled for desktop
* - PWA: Disabled for desktop (via build exclusion)
*/
import { defineConfig } from "vite";
@ -140,8 +139,8 @@ export default defineConfig(async () => {
define: {
...baseConfig.define,
'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__': JSON.stringify(true),
'__IS_DESKTOP__': JSON.stringify(true),

12
vite.config.optimized.mts

@ -24,14 +24,8 @@ export async function createOptimizedBuildConfig(mode: string): Promise<UserConf
const isElectron = mode === "electron";
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_PWA_ENABLED = isNative ? 'false' : 'true';
process.env.VITE_DISABLE_PWA = isNative ? 'true' : 'false';
if (isNative) {
process.env.VITE_PWA_ENABLED = 'false';
}
return {
base: "/",
@ -93,8 +87,8 @@ export async function createOptimizedBuildConfig(mode: string): Promise<UserConf
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'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()),
__IS_MOBILE__: JSON.stringify(isCapacitor),
__IS_ELECTRON__: JSON.stringify(isElectron),

2
vite.config.web.mts

@ -88,7 +88,7 @@ export default defineConfig(async ({ mode }) => {
// Enable PWA in all web environments for consistent testing
devOptions: {
enabled: true, // ✅ Enable in all environments
type: 'module'
type: 'classic'
},
workbox: {
cleanupOutdatedCaches: true,

Loading…
Cancel
Save