/** * The one definition of a release build, so the build script, the size scripts * and the smoke tests cannot drift apart: * Bun bundle + minify, `__DEV__` folded to false, then the Terser pass that * mangles internal property names (scripts/minify.ts). * * The compiler is pebble's own consumer compiler (pebble/plugin) and bundles * import "pebble", which is bundled IN — a prebuilt component needs nothing * else. `splitting` keeps polyfill-style lazy dynamic imports as separate * chunks: native engines never download their bytes. */ import compiler from "@pebble/pebble/plugin"; import { shrink } from "./minify"; /** Constants folded at build time. `__DEV__` strips development-only messages. */ export const RELEASE_DEFINE = { __DEV__: "false" } as const; export async function bundleRelease(entrypoints: string[], outdir?: string, sourcemap?: "linked" | "none", naming?: string) { const result = await Bun.build({ entrypoints, outdir, target: "browser", minify: true, sourcemap, naming, define: { ...RELEASE_DEFINE }, plugins: [compiler], splitting: true, }); if (!result.success) throw new AggregateError(result.logs, `build failed: ${entrypoints.join(", ")}`); return result; } /** Build one entrypoint and return the shipped code of its entry chunk. */ export async function buildRelease(entry: string): Promise { const result = await bundleRelease([entry]); const output = result.outputs.find(o => o.kind === "entry-point") ?? result.outputs[0]; return shrink(await output.text()); }