diff --git a/BUILDING.md b/BUILDING.md index 5f7dcd85..996d6573 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -634,3 +634,19 @@ For iOS deep links, configure the URL scheme in Xcode: | `web` | web | true | false | Standard web browser | | `capacitor` | capacitor | false | true | Mobile app (iOS/Android) | | `electron` | electron | false | true | Desktop app (Windows/macOS/Linux) | + +## Electron Build: CSS Injection + +The Electron build now uses Vite's built-in CSS handling with a custom plugin (`electron-css-injection`) that automatically injects CSS links into the generated `index.html` file. This replaces the previous manual CSS injection script. + +**Plugin:** `vite.config.electron.mts` - `electron-css-injection` plugin + +**Features:** +- Automatically detects and injects CSS files generated by Vite +- Ensures proper relative paths for Electron builds +- Handles multiple CSS files if present +- Provides detailed logging during build process + +**No manual intervention required** - CSS injection is handled automatically during the Vite build process. + +**Author:** Matthew Raymer diff --git a/doc/build-modernization-context.md b/doc/build-modernization-context.md new file mode 100644 index 00000000..133c2ad6 --- /dev/null +++ b/doc/build-modernization-context.md @@ -0,0 +1,51 @@ +# TimeSafari Build Modernization Context + +**Author:** Matthew Raymer + +## Motivation +- Eliminate manual hacks and post-build scripts for Electron builds +- Ensure maintainability, reproducibility, and security of build outputs +- Unify build, test, and deployment scripts for developer experience and CI/CD + +## Key Technical Decisions +- **Vite is the single source of truth for build output** + - All Electron build output (main process, preload, renderer HTML/CSS/JS) is managed by `vite.config.electron.mts` +- **CSS injection for Electron is handled by a Vite plugin** + - No more manual HTML/CSS edits or post-build scripts +- **Build scripts are unified and robust** + - Use `./scripts/build-electron.sh` for all Electron builds + - No more `fix-inject-css.js` or similar hacks +- **Output structure is deterministic and ASAR-friendly** + - Main process: `dist-electron/main.js` + - Preload: `dist-electron/preload.js` + - Renderer assets: `dist-electron/www/` (HTML, CSS, JS) + +## Security & Maintenance Checklist +- [x] All scripts and configs are committed and documented +- [x] No manual file hacks remain +- [x] All build output is deterministic and reproducible +- [x] No sensitive data is exposed in the build process +- [x] Documentation (`BUILDING.md`) is up to date + +## How to Build Electron +1. Run: + ```bash + ./scripts/build-electron.sh + ``` +2. Output will be in `dist-electron/`: + - `main.js`, `preload.js` in root + - `www/` contains all renderer assets +3. No manual post-processing is required + +## Customization +- **Vite config:** All build output and asset handling is controlled in `vite.config.electron.mts` +- **CSS/HTML injection:** Use Vite plugins (see `electron-css-injection` in the config) for further customization +- **Build scripts:** All orchestration is in `scripts/` and documented in `BUILDING.md` + +## For Future Developers +- Always use Vite plugins/config for build output changes +- Never manually edit built files or inject assets post-build +- Keep documentation and scripts in sync with the build process + +--- +This file documents the context and rationale for the build modernization and should be included in the repository for onboarding and future reference. \ No newline at end of file diff --git a/scripts/build-electron.js b/scripts/build-electron.js index 6f7a7a3e..74f172ea 100644 --- a/scripts/build-electron.js +++ b/scripts/build-electron.js @@ -12,59 +12,53 @@ if (!fs.existsSync(wwwPath)) { fs.mkdirSync(wwwPath, { recursive: true }); } -// Create a platform-specific index.html for Electron -const initialIndexContent = ` - -
- - - - -