remove the remainder of PWA functionality that wasn't being used, and fix the web "share target"
This commit is contained in:
+35
-201
@@ -1860,34 +1860,17 @@ npm run build:android:assets
|
||||
|
||||
### Build Process Overview
|
||||
|
||||
TimeSafari's build system follows a multi-stage process that prepares assets,
|
||||
combines scripts, and generates platform-specific outputs.
|
||||
TimeSafari's build system follows a multi-stage process that prepares assets
|
||||
and generates platform-specific outputs.
|
||||
|
||||
#### Pre-Build Preparation
|
||||
|
||||
##### 1. Service Worker Script Preparation
|
||||
|
||||
```bash
|
||||
# Optional: Format third-party service worker scripts
|
||||
npx prettier --write ./sw_scripts/
|
||||
```
|
||||
|
||||
**What this does:**
|
||||
|
||||
- Formats cryptographic libraries (`nacl.js`, `noble-curves.js`,
|
||||
`noble-hashes.js`, etc.)
|
||||
- These scripts are automatically combined during the build process
|
||||
- Improves readability and makes version control diffs cleaner
|
||||
- **Note**: This is optional and only needed when updating third-party scripts
|
||||
|
||||
**2. Automatic Pre-Build Steps**
|
||||
The `prebuild` script automatically runs before any build:
|
||||
#### Pre-Build Script
|
||||
|
||||
```json
|
||||
"prebuild": "eslint --ext .js,.ts,.vue --ignore-path .gitignore src && node scripts/copy-wasm.js"
|
||||
```
|
||||
|
||||
npm runs `prebuild` only before a script named `build`. This project defines no `build` script, so none of the `build:*` commands trigger it.
|
||||
npm runs `prebuild` only before a script named `build`. This project defines
|
||||
no `build` script, so none of the `build:*` commands trigger it.
|
||||
|
||||
**What it does when run:**
|
||||
|
||||
@@ -1899,8 +1882,8 @@ npm runs `prebuild` only before a script named `build`. This project defines no
|
||||
**Web Build Process:**
|
||||
|
||||
```text
|
||||
1. Pre-Build: ESLint + Script Combination + WASM Copy
|
||||
2. Environment Setup: Load .env files, set NODE_ENV
|
||||
1. Environment Setup: Load .env files, set NODE_ENV
|
||||
2. Type Check: tsc --noEmit (test and production modes)
|
||||
3. Vite Build: Bundle web assets
|
||||
4. Output: Production-ready files in dist/
|
||||
```
|
||||
@@ -1925,34 +1908,6 @@ npm runs `prebuild` only before a script named `build`. This project defines no
|
||||
5. Package Creation: APK/IPA generation
|
||||
```
|
||||
|
||||
#### Service Worker Architecture
|
||||
|
||||
**Script Organization:**
|
||||
|
||||
- `sw_scripts/` - Individual third-party scripts
|
||||
- `sw_combine.js` - Combines scripts into single file
|
||||
- `sw_scripts-combined.js` - Combined service worker (317KB, 10K+ lines)
|
||||
- `vite.config.utils.mts` - PWA configuration using combined script
|
||||
|
||||
**PWA Integration:**
|
||||
|
||||
```typescript
|
||||
// vite.config.utils.mts
|
||||
pwaConfig: {
|
||||
strategies: "injectManifest",
|
||||
filename: "sw_scripts-combined.js", // Uses our combined script
|
||||
// ... manifest configuration
|
||||
}
|
||||
```
|
||||
|
||||
**What Gets Combined:**
|
||||
|
||||
- `nacl.js` - NaCl cryptographic library
|
||||
- `noble-curves.js` - Elliptic curve cryptography (177KB)
|
||||
- `noble-hashes.js` - Cryptographic hash functions (91KB)
|
||||
- `safari-notifications.js` - Safari-specific notifications
|
||||
- `additional-scripts.js` - Additional service worker functionality
|
||||
|
||||
#### Process Environment Configuration
|
||||
|
||||
**Environment Files:**
|
||||
@@ -2005,10 +1960,13 @@ device)
|
||||
```folders
|
||||
dist/
|
||||
├── index.html # Main HTML file
|
||||
├── assets/ # Bundled JavaScript/CSS
|
||||
├── sw.js # Service worker (injected)
|
||||
├── manifest.webmanifest # PWA manifest
|
||||
└── wasm/ # SQLite WASM files
|
||||
├── assets/ # Bundled JavaScript, CSS, and SQLite WASM
|
||||
├── img/ # Static images (copied from public/)
|
||||
├── models/ # Static model files (copied from public/)
|
||||
├── favicon.ico
|
||||
├── manifest.webmanifest # Web app manifest, incl. share_target (copied from public/)
|
||||
├── robots.txt
|
||||
└── sw.js # Service worker for the Web Share Target (copied from public/)
|
||||
```
|
||||
|
||||
**Electron Build:**
|
||||
@@ -2030,17 +1988,14 @@ electron/
|
||||
**Manual Steps (Developer Responsibility):**
|
||||
|
||||
- Database migration testing
|
||||
- Service worker script formatting (optional)
|
||||
- Version updates and changelog
|
||||
- Environment-specific builds
|
||||
|
||||
**Automatic Steps (Build System):**
|
||||
|
||||
- Code linting and formatting
|
||||
- Script combination
|
||||
- Type checking (test and production builds)
|
||||
- Asset optimization
|
||||
- Package creation
|
||||
- Service worker injection
|
||||
|
||||
This architecture ensures consistent builds across all platforms while providing
|
||||
flexibility for platform-specific optimizations and manual quality assurance steps.
|
||||
@@ -2445,9 +2400,7 @@ export async function createBuildConfig(platform: string): Promise<UserConfig> {
|
||||
const appConfig = await loadAppConfig();
|
||||
const isCapacitor = platform === "capacitor";
|
||||
const isElectron = platform === "electron";
|
||||
const isNative = isCapacitor || isElectron;
|
||||
|
||||
// Set platform - PWA is always enabled for web platforms
|
||||
process.env.VITE_PLATFORM = platform;
|
||||
|
||||
return {
|
||||
@@ -2463,7 +2416,6 @@ export async function createBuildConfig(platform: string): Promise<UserConfig> {
|
||||
assetsDir: 'assets',
|
||||
chunkSizeWarningLimit: 1000,
|
||||
rollupOptions: {
|
||||
external: isNative ? ['@capacitor/app'] : [],
|
||||
output: {
|
||||
format: 'esm',
|
||||
generatedCode: { preset: 'es2015' },
|
||||
@@ -2495,12 +2447,7 @@ export async function createBuildConfig(platform: string): Promise<UserConfig> {
|
||||
'@jlongster/sql.js',
|
||||
'absurd-sql',
|
||||
// ... additional dependencies
|
||||
],
|
||||
exclude: isNative ? [
|
||||
'register-service-worker',
|
||||
'workbox-window',
|
||||
// ... native exclusions
|
||||
] : []
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -2523,98 +2470,23 @@ export async function createBuildConfig(platform: string): Promise<UserConfig> {
|
||||
|
||||
**File**: `vite.config.web.mts`
|
||||
**Author**: Matthew Raymer
|
||||
**Description**: Vite configuration for web platform with PWA support
|
||||
**Description**: Vite configuration for the web platform
|
||||
|
||||
**Purpose**: Configures Vite for web builds with environment-specific
|
||||
optimizations and PWA features.
|
||||
**Purpose**: Configures Vite for web builds by delegating to the common
|
||||
configuration with the `web` platform.
|
||||
|
||||
**Configuration Structure**:
|
||||
|
||||
```typescript
|
||||
export default defineConfig(async () => createBuildConfig('web'));
|
||||
```
|
||||
|
||||
**Key Features**:
|
||||
|
||||
- **Environment-Specific Configuration**: Different settings for dev/test/prod
|
||||
- **PWA Integration**: Progressive Web App support with service worker
|
||||
- **Build Optimization**: Manual chunk splitting for better caching
|
||||
- **Source Maps**: Environment-specific source map configuration
|
||||
- **Caching Strategies**: Production-specific API caching
|
||||
|
||||
**Environment Configurations**:
|
||||
|
||||
**Development Mode**:
|
||||
|
||||
```typescript
|
||||
{
|
||||
build: {
|
||||
minify: false,
|
||||
sourcemap: true,
|
||||
rollupOptions: { output: { manualChunks: undefined } }
|
||||
},
|
||||
define: {
|
||||
__DEV__: true,
|
||||
__TEST__: false,
|
||||
__PROD__: false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Test Mode**:
|
||||
|
||||
```typescript
|
||||
{
|
||||
build: {
|
||||
minify: false,
|
||||
sourcemap: true,
|
||||
rollupOptions: { output: { manualChunks: undefined } }
|
||||
},
|
||||
define: {
|
||||
__DEV__: false,
|
||||
__TEST__: true,
|
||||
__PROD__: false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Production Mode**:
|
||||
|
||||
```typescript
|
||||
{
|
||||
build: {
|
||||
minify: 'terser',
|
||||
sourcemap: false,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks: {
|
||||
vendor: ['vue', 'vue-router', 'pinia'],
|
||||
utils: ['luxon', 'ramda', 'zod'],
|
||||
crypto: ['@ethersproject/wallet', '@ethersproject/hdnode'],
|
||||
sql: ['@jlongster/sql.js', 'absurd-sql']
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
define: {
|
||||
__DEV__: false,
|
||||
__TEST__: false,
|
||||
__PROD__: true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**PWA Configuration**:
|
||||
|
||||
```typescript
|
||||
VitePWA({
|
||||
registerType: 'autoUpdate',
|
||||
manifest: appConfig.pwaConfig?.manifest,
|
||||
devOptions: { enabled: true, type: 'classic' },
|
||||
workbox: {
|
||||
cleanupOutdatedCaches: true,
|
||||
skipWaiting: true,
|
||||
clientsClaim: true,
|
||||
sourcemap: mode !== 'production',
|
||||
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024,
|
||||
runtimeCaching: mode === 'production' ? [/* API caching */] : []
|
||||
}
|
||||
})
|
||||
```
|
||||
- **Minimal Configuration**: Inherits all settings from `vite.config.common.mts`
|
||||
- **Mode Selection**: `--mode test` or `--mode production` (passed by
|
||||
`scripts/build-web.sh`) selects the matching `.env.*` file
|
||||
- **Output**: Writes to `dist/`
|
||||
|
||||
### B.3 vite.config.electron.mts
|
||||
|
||||
@@ -2705,7 +2577,6 @@ export default defineConfig(async () => createBuildConfig('capacitor'));
|
||||
|
||||
- **Minimal Configuration**: Inherits all settings from common config
|
||||
- **Mobile Platform**: Automatically configures for mobile-specific settings
|
||||
- **PWA Disabled**: Progressive Web App features disabled for native apps
|
||||
- **Native Dependencies**: Handles Capacitor-specific dependencies
|
||||
|
||||
### B.5 vite.config.utils.mts
|
||||
@@ -2714,51 +2585,15 @@ export default defineConfig(async () => createBuildConfig('capacitor'));
|
||||
**Author**: Matthew Raymer
|
||||
**Description**: Utility functions for Vite configuration
|
||||
|
||||
**Purpose**: Provides shared configuration loading and PWA manifest generation.
|
||||
**Purpose**: Provides the shared alias configuration and strict ESBuild settings.
|
||||
|
||||
**Key Functions**:
|
||||
|
||||
**loadPackageJson()**: Loads and parses package.json for app configuration
|
||||
**loadAppConfig()**: Returns the alias configuration used by the common and
|
||||
optimized configs
|
||||
|
||||
**loadAppConfig()**: Loads complete application configuration including PWA settings
|
||||
|
||||
**PWA Configuration**:
|
||||
|
||||
```typescript
|
||||
interface PWAConfig {
|
||||
registerType: string;
|
||||
strategies: string;
|
||||
srcDir: string;
|
||||
filename: string;
|
||||
manifest: {
|
||||
name: string;
|
||||
short_name: string;
|
||||
theme_color: string;
|
||||
background_color: string;
|
||||
icons: ManifestIcon[];
|
||||
share_target: ShareTarget;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
**Manifest Icons**:
|
||||
|
||||
- Android Chrome 192x192 PNG
|
||||
- Android Chrome 512x512 PNG
|
||||
- Maskable icons for adaptive UI
|
||||
|
||||
**Share Target Configuration**:
|
||||
|
||||
```typescript
|
||||
share_target: {
|
||||
action: "/share-target",
|
||||
method: "POST",
|
||||
enctype: "multipart/form-data",
|
||||
params: {
|
||||
files: [{ name: "photo", accept: ["image/*"] }]
|
||||
}
|
||||
}
|
||||
```
|
||||
**getStrictESBuildConfig()**: Returns ESBuild settings that fail the build on
|
||||
syntax and duplicate-declaration errors
|
||||
|
||||
**Alias Configuration**:
|
||||
|
||||
@@ -2826,8 +2661,7 @@ All scripts use consistent error handling:
|
||||
|
||||
**Web Platform**:
|
||||
|
||||
- PWA features enabled
|
||||
- Service worker injection
|
||||
- Requires a secure context (HTTPS, `localhost`, `127.0.0.1`, or `[::1]`)
|
||||
- Browser-specific optimizations
|
||||
|
||||
**Electron Platform**:
|
||||
|
||||
Reference in New Issue
Block a user