2026-05-11 16:12:34 +02:00
|
|
|
// Build entry point. Run via `bun run build` (or transitively via
|
|
|
|
|
// `bun run lint` / `package` / `start`).
|
|
|
|
|
//
|
|
|
|
|
// Output: a self-contained `dist/` directory that web-ext consumes as its
|
|
|
|
|
// sourceDir. The bundler inlines `vendor/qrcode.js` into the popup script
|
|
|
|
|
// (via the ESM import in popup.js), so the published extension is one JS
|
|
|
|
|
// file plus the static HTML/CSS/icon/license assets.
|
|
|
|
|
//
|
|
|
|
|
// Anything outside `dist/` never ships, so this script is the single source
|
|
|
|
|
// of truth for "what is the extension."
|
|
|
|
|
|
2026-05-11 16:04:22 +02:00
|
|
|
import { rm, cp } from "node:fs/promises";
|
|
|
|
|
|
|
|
|
|
const DIST = "dist";
|
|
|
|
|
|
|
|
|
|
await rm(DIST, { recursive: true, force: true });
|
|
|
|
|
|
|
|
|
|
const result = await Bun.build({
|
|
|
|
|
entrypoints: ["popup/popup.js"],
|
|
|
|
|
outdir: `${DIST}/popup`,
|
|
|
|
|
target: "browser",
|
|
|
|
|
format: "esm",
|
|
|
|
|
minify: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!result.success) {
|
|
|
|
|
for (const log of result.logs) console.error(log);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
|
cp("manifest.json", `${DIST}/manifest.json`),
|
|
|
|
|
cp("popup/popup.html", `${DIST}/popup/popup.html`),
|
|
|
|
|
cp("popup/popup.css", `${DIST}/popup/popup.css`),
|
|
|
|
|
cp("icons", `${DIST}/icons`, { recursive: true }),
|
|
|
|
|
cp("vendor/LICENSE.qrcode-generator", `${DIST}/LICENSE.qrcode-generator`),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const size = (await Bun.file(`${DIST}/popup/popup.js`).arrayBuffer()).byteLength;
|
|
|
|
|
console.log(`Built ${DIST}/ (popup.js: ${(size / 1024).toFixed(1)} KB)`);
|