askrobots / dbbasic-browser
Public
A desktop browser with x402 built in: when a page asks for payment, it pays in stablecoins and shows the content.
danq9
toolbar: Back and Forward are greyed out when there's nowhere to go
cc08c7a
1 week, 2 days ago
History
build-standalone.mjs · 2.2 KB · 43 lines
| 1 | #!/usr/bin/env node |
| 2 | /** |
| 3 | * A self-contained build: everything except Electron itself is bundled into one folder, so the app can be run with |
| 4 | * nothing but an Electron binary — no npm install and no Node version requirement on the machine that runs it. |
| 5 | * |
| 6 | * npm run build:standalone → standalone/ (copy this folder anywhere) |
| 7 | * <electron> standalone/ e.g. ./electron standalone/ --user-data-dir=<a folder of its own> |
| 8 | * |
| 9 | * On Linux, Chromium's sandbox needs either unprivileged user namespaces or a setuid chrome-sandbox helper. Where neither is |
| 10 | * available, prefer an AppArmor profile that allows user namespaces for this one binary, or make the helper setuid root once |
| 11 | * (chown root chrome-sandbox && chmod 4755 chrome-sandbox). Do not use --no-sandbox for pages you do not trust. |
| 12 | * |
| 13 | * It is the normal build plus the three SDK packages that the normal build leaves external (viem, anthropic, openai). |
| 14 | */ |
| 15 | import { build } from "esbuild"; |
| 16 | import { copyFileSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
| 17 | import { dirname, join } from "node:path"; |
| 18 | import { fileURLToPath } from "node:url"; |
| 19 | |
| 20 | const root = join(dirname(fileURLToPath(import.meta.url)), ".."); |
| 21 | const out = join(root, "standalone"); |
| 22 | rmSync(out, { recursive: true, force: true }); |
| 23 | mkdirSync(out, { recursive: true }); |
| 24 | |
| 25 | await build({ |
| 26 | entryPoints: [join(root, "src", "main.ts")], |
| 27 | bundle: true, |
| 28 | platform: "node", |
| 29 | format: "esm", |
| 30 | external: ["electron"], |
| 31 | outfile: join(out, "main.js"), |
| 32 | // Bundled CommonJS packages call require(); give them one. |
| 33 | banner: { js: 'import { createRequire as __cr } from "node:module"; const require = __cr(import.meta.url);' }, |
| 34 | logLevel: "warning", |
| 35 | }); |
| 36 | |
| 37 | // The rest of what the normal build puts in dist/ (it must have been built first). |
| 38 | for (const f of ["chrome.html", "help.html", "preload.cjs", "webview-preload.cjs", "icon.png", "Readability.js", "reader-extractor.js"]) { |
| 39 | copyFileSync(join(root, "dist", f), join(out, f)); |
| 40 | } |
| 41 | const version = JSON.parse(readFileSync(join(root, "package.json"), "utf8")).version; |
| 42 | writeFileSync(join(out, "package.json"), JSON.stringify({ name: "dbbasic-browser-standalone", version, type: "module", main: "main.js" }, null, 2) + "\n"); |
| 43 | console.log(`standalone build: ${out}`); |