aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md105
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
3A bare-bones Electron + TypeScript + [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) app.
4No 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```
17minimal-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
38git clone <this-repo>
39cd minimal-electron-bsql
40npm install
41```
42
43ℹ️ On install, native modules are rebuilt for your Electron version via `@electron/rebuild`.
44
45
46
47Scripts
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
58In src/main/index.ts:
59
601. Database file created at app.getPath('userData')/app.db
612. A table messages is created (if not exists)
623. One row "hello from better-sqlite3" is inserted
634. A SELECT runs and the row is logged to console
645. Window shows renderer/index.html → just <main>hi</main>
65
66
67
68Packaging 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
79npm run dist -- --mac arm64
80npm run dist -- --mac x64
81```
82
83- Optionally merge into a universal binary:
84
85```bash
86npx 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
93Common 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
105MIT