-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathelectron-builder.config.js
More file actions
184 lines (161 loc) · 6.03 KB
/
electron-builder.config.js
File metadata and controls
184 lines (161 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
const path = require("path");
const fs = require("fs");
// --- afterPack: strip bloat from the asar archive ---
// electron-builder v26 has a bug where the `files` config (negation-only,
// positive whitelist, AND FileSet with filter) is only applied to
// nodeModuleFilePatterns (node_modules filtering), NOT to the app directory
// walker (firstOrDefaultFilePatterns). Even the built-in default exclusions
// (e.g. !**/{.git,...}) don't work — .git ends up in the asar.
//
// Workaround: afterPack runs after the asar is packed. We extract it, keep
// ONLY what the app needs at runtime (whitelist), and repack.
const KEEP_ENTRIES = new Set([
"package.json",
"index.html",
"dist", // Vite-bundled renderer output
"electron", // tsup-compiled main/preload (electron/dist/)
"node_modules", // production dependencies (already filtered by electron-builder)
]);
async function afterPackHook(context) {
const resourcesDir = ["darwin", "mas"].includes(context.electronPlatformName)
? path.join(context.appOutDir, `${context.packager.appInfo.productFilename}.app`, "Contents", "Resources")
: path.join(context.appOutDir, "resources");
const asarPath = path.join(resourcesDir, "app.asar");
if (!fs.existsSync(asarPath)) return;
// @electron/asar is a transitive dep of electron-builder, always available
const asar = require("@electron/asar");
const tmpDir = path.join(resourcesDir, "_asar_tmp");
console.log(" \u2022 afterPack: extracting asar to strip bloat...");
asar.extractAll(asarPath, tmpDir);
// Remove everything not in the whitelist
const entries = fs.readdirSync(tmpDir);
for (const entry of entries) {
if (!KEEP_ENTRIES.has(entry)) {
fs.rmSync(path.join(tmpDir, entry), { recursive: true, force: true });
}
}
// Inside electron/, keep only dist/ (compiled JS), remove src/ and other dev files
const electronDir = path.join(tmpDir, "electron");
if (fs.existsSync(electronDir)) {
for (const sub of fs.readdirSync(electronDir)) {
if (sub !== "dist") {
fs.rmSync(path.join(electronDir, sub), { recursive: true, force: true });
}
}
}
console.log(" \u2022 afterPack: repacking asar...");
fs.rmSync(asarPath, { force: true });
await asar.createPackage(tmpDir, asarPath);
fs.rmSync(tmpDir, { recursive: true, force: true });
// Log final size for visibility
const finalSize = fs.statSync(asarPath).size;
const mb = (finalSize / 1024 / 1024).toFixed(1);
console.log(` \u2022 afterPack: asar cleaned \u2014 ${mb} MB`);
}
/** @type {import('electron-builder').Configuration} */
module.exports = {
appId: "com.harnss.app",
productName: "Harnss",
directories: {
output: "release/${version}",
buildResources: "build",
},
// --- Files to include in the app ---
// NOTE: Due to electron-builder v26 bug, these patterns only affect
// nodeModuleFilePatterns (node_modules filtering). App directory exclusions
// are handled by the afterPack hook above which strips bloat from the asar.
files: [
"!**/{test,tests,__tests__,__mocks__,spec,specs}/**",
"!**/*.d.ts",
"!**/*.d.cts",
"!**/*.d.mts",
"!**/*.map",
],
// --- ASAR packing ---
asar: true,
asarUnpack: [
"node_modules/node-pty/**",
"node_modules/electron-liquid-glass/**",
"node_modules/@anthropic-ai/claude-agent-sdk/cli.js",
"node_modules/@anthropic-ai/claude-agent-sdk/*.wasm",
"node_modules/@anthropic-ai/claude-agent-sdk/vendor/**",
"node_modules/@anthropic-ai/claude-agent-sdk/manifest*.json",
],
npmRebuild: true,
nodeGypRebuild: false,
includePdb: false,
afterPack: afterPackHook,
// --- macOS ---
mac: {
target: ["dmg", "zip"],
category: "public.app-category.developer-tools",
icon: "build/icon.icon",
darkModeSupport: true,
hardenedRuntime: true,
gatekeeperAssess: false,
entitlements: "build/entitlements.mac.plist",
entitlementsInherit: "build/entitlements.mac.plist",
extendInfo: {
NSMicrophoneUsageDescription: "Harnss uses the microphone for voice dictation to transcribe speech into text.",
},
},
dmg: {
icon: "build/icon.icns",
contents: [
{ x: 130, y: 220 },
{ x: 410, y: 220, type: "link", path: "/Applications" },
],
window: { width: 540, height: 380 },
},
// --- Windows ---
win: {
target: [{ target: "nsis", arch: ["x64", "arm64"] }],
icon: "build/icon.ico",
files: [
"!node_modules/electron-liquid-glass/**",
"!node_modules/@anthropic-ai/claude-agent-sdk/vendor/ripgrep/arm64-darwin/**",
"!node_modules/@anthropic-ai/claude-agent-sdk/vendor/ripgrep/x64-darwin/**",
"!node_modules/@anthropic-ai/claude-agent-sdk/vendor/ripgrep/arm64-linux/**",
"!node_modules/@anthropic-ai/claude-agent-sdk/vendor/ripgrep/x64-linux/**",
"!node_modules/node-pty/prebuilds/darwin-*/**",
"!node_modules/node-pty/prebuilds/linux-*/**",
],
},
nsis: {
oneClick: false,
allowToChangeInstallationDirectory: true,
perMachine: false,
deleteAppDataOnUninstall: false,
// Include arch in filename so x64 and arm64 installers don't collide
artifactName: "${productName}-Setup-${version}-${arch}.${ext}",
},
// --- Linux ---
linux: {
target: [
{ target: "AppImage" },
{ target: "deb" },
],
category: "Development",
icon: "build/icon.png",
files: [
"!node_modules/electron-liquid-glass/**",
"!node_modules/@anthropic-ai/claude-agent-sdk/vendor/ripgrep/arm64-darwin/**",
"!node_modules/@anthropic-ai/claude-agent-sdk/vendor/ripgrep/x64-darwin/**",
"!node_modules/@anthropic-ai/claude-agent-sdk/vendor/ripgrep/arm64-win32/**",
"!node_modules/@anthropic-ai/claude-agent-sdk/vendor/ripgrep/x64-win32/**",
"!node_modules/node-pty/prebuilds/darwin-*/**",
"!node_modules/node-pty/prebuilds/win32-*/**",
],
},
deb: {
depends: ["libnotify4", "libsecret-1-0"],
},
// --- Auto-update ---
publish: {
provider: "github",
owner: "OpenSource03",
repo: "harnss",
releaseType: "release",
},
afterSign: "scripts/notarize.js",
};