// Bundle the typed Preact app and its standalone inference worker, and copy // the shared rules module (core/wasm/pkg, built by core/wasm/build.sh) beside them. // Usage: node site/bundle.mjs OUT_DIR. No environment variables are read. import { build } from "esbuild"; import { copyFileSync, existsSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { resolve } from "node:path"; const root = fileURLToPath(new URL("..", import.meta.url)); if (process.argv.length !== 3) throw new Error("Usage: node site/bundle.mjs OUT_DIR"); const core = resolve(root, "core/wasm/pkg/tokenling_core_bg.wasm"); if (!existsSync(core)) throw new Error("Build the shared rules first: core/wasm/build.sh"); await build({ absWorkingDir: root, entryPoints: { main: "web/main.tsx", brain: "web/brain.ts" }, outdir: resolve(process.argv[2]), bundle: true, format: "esm", platform: "browser", target: "es2022", minify: true, sourcemap: true, legalComments: "eof", // No split chunks: the offline resource manifest is main.js, brain.js and the rules module. splitting: false, }); // Both bundles load the module from beside themselves (web/core.ts). copyFileSync(core, resolve(process.argv[2], "tokenling_core_bg.wasm"));