tobogganSe connecter

library

Prebuilt pebble components: drop-in custom elements, no compiler needed

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

Dernier runAucun
0Étoiles
0Forks
2Issues
39 lignes · 1576 octetsBrut · Historique
1/**
2 * The one definition of a release build, so the build script, the size scripts
3 * and the smoke tests cannot drift apart:
4 * Bun bundle + minify, `__DEV__` folded to false, then the Terser pass that
5 * mangles internal property names (scripts/minify.ts).
6 *
7 * The compiler is pebble's own consumer compiler (pebble/plugin) and bundles
8 * import "pebble", which is bundled IN — a prebuilt component needs nothing
9 * else. `splitting` keeps polyfill-style lazy dynamic imports as separate
10 * chunks: native engines never download their bytes.
11 */
12import compiler from "@pebble/pebble/plugin";
13import { shrink } from "./minify";
14
15/** Constants folded at build time. `__DEV__` strips development-only messages. */
16export const RELEASE_DEFINE = { __DEV__: "false" } as const;
17
18export async function bundleRelease(entrypoints: string[], outdir?: string, sourcemap?: "linked" | "none", naming?: string) {
19 const result = await Bun.build({
20 entrypoints,
21 outdir,
22 target: "browser",
23 minify: true,
24 sourcemap,
25 naming,
26 define: { ...RELEASE_DEFINE },
27 plugins: [compiler],
28 splitting: true,
29 });
30 if (!result.success) throw new AggregateError(result.logs, `build failed: ${entrypoints.join(", ")}`);
31 return result;
32}
33
34/** Build one entrypoint and return the shipped code of its entry chunk. */
35export async function buildRelease(entry: string): Promise<string> {
36 const result = await bundleRelease([entry]);
37 const output = result.outputs.find(o => o.kind === "entry-point") ?? result.outputs[0];
38 return shrink(await output.text());
39}