import { rm } from "node:fs/promises"; import { fileURLToPath } from "node:url"; const executablePath = fileURLToPath(new URL("../dist/dial-server", import.meta.url)); const entrypoint = fileURLToPath(new URL("../src/server/main.ts", import.meta.url)); await rm(executablePath, { force: true }); const target = process.env["BUN_TARGET"] ?? process.env["BUILD_TARGET"]; const result = await Bun.build({ compile: target ? { autoloadBunfig: true, autoloadDotenv: true, outfile: executablePath, target: target as Bun.Build.CompileTarget, } : { autoloadBunfig: true, autoloadDotenv: true, outfile: executablePath, }, entrypoints: [entrypoint], minify: true, sourcemap: "linked", }); if (!result.success) { console.error("构建失败:", result.logs); process.exit(1); } console.log(`Built executable: ${executablePath}`);