// One script builds both bundles so they share one identifier: the server refuses clients of other builds. import { randomUUID } from 'node:crypto'; const define = JSON.stringify(randomUUID()); const args = process.argv.slice(2).filter((arg, index) => index > 0 || arg !== '--'); // `ng build` empties its output path, so the server bundle has to come after it. const ng = Bun.spawn( ['bun', 'run', 'ng', 'build', '--define', `PLANNING_BUILD=${define}`, ...args], { stdio: ['inherit', 'inherit', 'inherit'], // Angular skips its chunk optimization below three lazy chunks, which splits the initial bundle. env: { NG_BUILD_OPTIMIZE_CHUNKS: '1', ...process.env }, }, ); const code = await ng.exited; if (code !== 0) process.exit(code); const result = await Bun.build({ entrypoints: ['src/server.ts', 'src/app/services/leave-planner.worker.ts'], target: 'bun', outdir: 'dist/vac-optimizer/server', naming: '[name].[ext]', define: { PLANNING_BUILD: define }, }); for (const log of result.logs) console.log(log); if (!result.success) process.exit(1);