diff options
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..f74d4fc --- /dev/null +++ b/README.md | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | # minimal-electron-bsql | ||
| 2 | |||
| 3 | A bare-bones Electron + TypeScript + [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) app. | ||
| 4 | No forge, no boilerplate, no scaffolding. Just the absolute minimum setup that: | ||
| 5 | |||
| 6 | - Runs in dev mode on macOS/Linux/Windows | ||
| 7 | - Uses `better-sqlite3` from the **main process** | ||
| 8 | - Creates a SQLite DB at startup, inserts + selects a row | ||
| 9 | - Displays a trivial HTML UI | ||
| 10 | - Can be packaged for distribution (SQLite included) | ||
| 11 | |||
| 12 | --- | ||
| 13 | |||
| 14 | ## Project structure | ||
| 15 | |||
| 16 | ``` | ||
| 17 | minimal-electron-bsql/ | ||
| 18 | ├── src/ | ||
| 19 | │ └── main/ | ||
| 20 | │ └── index.ts # Electron main process | ||
| 21 | ├── renderer/ | ||
| 22 | │ └── index.html # Minimal UI | ||
| 23 | ├── package.json | ||
| 24 | ├── tsconfig.json | ||
| 25 | ``` | ||
| 26 | |||
| 27 | ## Requirements | ||
| 28 | |||
| 29 | - Node.js ≥ 18 | ||
| 30 | - macOS (Apple Silicon or Intel). Windows & Linux should work with native build tools installed. | ||
| 31 | - Xcode Command Line Tools (macOS) or MSVC Build Tools (Windows) for native rebuilds | ||
| 32 | |||
| 33 | --- | ||
| 34 | |||
| 35 | ## Install | ||
| 36 | |||
| 37 | ```bash | ||
| 38 | git clone <this-repo> | ||
| 39 | cd minimal-electron-bsql | ||
| 40 | npm install | ||
| 41 | ``` | ||
| 42 | |||
| 43 | ℹ️ On install, native modules are rebuilt for your Electron version via `@electron/rebuild`. | ||
| 44 | |||
| 45 | ⸻ | ||
| 46 | |||
| 47 | Scripts | ||
| 48 | |||
| 49 | - npm run dev → compile TS and start Electron in dev mode | ||
| 50 | - npm run build → compile TypeScript only | ||
| 51 | - npm run start → start Electron with compiled code | ||
| 52 | - npm run rebuild → force-rebuild native modules (better-sqlite3) | ||
| 53 | - npm run dist → create distributable builds via electron-builder | ||
| 54 | - npm run pack → package into unpacked app directory | ||
| 55 | |||
| 56 | ## What happens on startup | ||
| 57 | |||
| 58 | In src/main/index.ts: | ||
| 59 | |||
| 60 | 1. Database file created at app.getPath('userData')/app.db | ||
| 61 | 2. A table messages is created (if not exists) | ||
| 62 | 3. One row "hello from better-sqlite3" is inserted | ||
| 63 | 4. A SELECT runs and the row is logged to console | ||
| 64 | 5. Window shows renderer/index.html → just <main>hi</main> | ||
| 65 | |||
| 66 | ⸻ | ||
| 67 | |||
| 68 | Packaging notes | ||
| 69 | • Native modules: better-sqlite3.node must live outside app.asar. This is handled via: | ||
| 70 | |||
| 71 | ``` | ||
| 72 | "asarUnpack": ["node_modules/better-sqlite3/**/*"] | ||
| 73 | ``` | ||
| 74 | |||
| 75 | - Cross-arch builds (macOS): | ||
| 76 | - Build separately for arm64 and x64: | ||
| 77 | |||
| 78 | ```bash | ||
| 79 | npm run dist -- --mac arm64 | ||
| 80 | npm run dist -- --mac x64 | ||
| 81 | ``` | ||
| 82 | |||
| 83 | - Optionally merge into a universal binary: | ||
| 84 | |||
| 85 | ```bash | ||
| 86 | npx electron-builder --universal | ||
| 87 | ``` | ||
| 88 | |||
| 89 | - Database location: Always use app.getPath('userData'). Do not write next to your code files, since those are inside app.asar when packaged. | ||
| 90 | |||
| 91 | ⸻ | ||
| 92 | |||
| 93 | Common pitfalls & fixes | ||
| 94 | |||
| 95 | - was compiled against a different Node.js version error | ||
| 96 | - Run npm run rebuild after npm install or upgrading Electron. | ||
| 97 | - .node module not found after packaging | ||
| 98 | - Check asarUnpack includes better-sqlite3. | ||
| 99 | - Windows/Linux builds | ||
| 100 | - Windows: install Build Tools for Visual Studio + Python | ||
| 101 | - Linux: sudo apt install build-essential python3 | ||
| 102 | |||
| 103 | ## License | ||
| 104 | |||
| 105 | MIT | ||
