From dce7ab817e84002de9f9383afbaab0ebd8a78f51 Mon Sep 17 00:00:00 2001 From: imbytecat Date: Sun, 18 Jan 2026 06:19:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E9=85=8D=E7=BD=AE=E5=B9=B6=E6=9B=B4=E6=96=B0=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构构建配置以使用映射表定义目标平台,并改进输出日志显示格式。 - 更新构建脚本以使用 `bun build.ts` 替代手动编译命令 --- build.ts | 41 ++++++++++++++++++++++++++--------------- package.json | 2 +- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/build.ts b/build.ts index 92d2f8b..0b266dd 100644 --- a/build.ts +++ b/build.ts @@ -1,23 +1,34 @@ -const targets = [ +const targetMap = { + 'bun-windows-x64': 'x86_64-pc-windows-msvc', + 'bun-darwin-arm64': 'aarch64-apple-darwin', + 'bun-darwin-x64': 'x86_64-apple-darwin', + 'bun-linux-x64': 'x86_64-unknown-linux-gnu', + 'bun-linux-arm64': 'aarch64-unknown-linux-gnu', +} as const + +type BunTarget = keyof typeof targetMap + +const targets: BunTarget[] = [ 'bun-windows-x64', 'bun-darwin-arm64', 'bun-linux-x64', -] as const +] -const outputs = await Promise.all( - targets.map((target) => - Bun.build({ - entrypoints: ['./.output/server/index.mjs'], - compile: { - outfile: `server-${target}`, - target, - }, - outdir: './out', - }), - ), +const buildTasks = targets.map((bunTarget) => + Bun.build({ + entrypoints: ['./.output/server/index.mjs'], + compile: { + outfile: `server-${targetMap[bunTarget]}`, + target: bunTarget, + }, + outdir: './out', + }), ) +const outputs = await Promise.all(buildTasks) + for (const [index, output] of outputs.entries()) { - console.log(`\n${targets[index]}:`) - console.log(output.outputs) + const task = buildTasks[index] + if (!task) continue + console.log(output.outputs.map((item) => item.path)) } diff --git a/package.json b/package.json index 911fc0d..fc267d4 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "type": "module", "scripts": { "build": "vite build && bun run compile", - "compile": "rm -rf out && bun build --compile .output/server/index.mjs --outfile out/server", + "compile": "rm -rf out && bun build.ts", "db:generate": "drizzle-kit generate", "db:migrate": "drizzle-kit migrate", "db:push": "drizzle-kit push",