ALIEZ 1 周之前
父節點
當前提交
29c624c71f
共有 1 個文件被更改,包括 17 次插入1 次删除
  1. 17 1
      scripts/build-with-env.mjs

+ 17 - 1
scripts/build-with-env.mjs

@@ -40,5 +40,21 @@ console.log(
   `[build-with-env] ${envFile} → NEXT_PUBLIC_APP_ENV=${env.NEXT_PUBLIC_APP_ENV}, API_PROXY_TARGET=${env.API_PROXY_TARGET}`,
 );
 
-const r = spawnSync("next", ["build"], { cwd: root, env, stdio: "inherit" });
+const nextCli = resolve(root, "node_modules/next/dist/bin/next");
+if (!existsSync(nextCli)) {
+  console.error("[build-with-env] 未找到 next,请先在项目目录执行 npm install");
+  process.exit(1);
+}
+
+const r = spawnSync(process.execPath, [nextCli, "build"], {
+  cwd: root,
+  env,
+  stdio: "inherit",
+});
+
+if (r.error) {
+  console.error("[build-with-env] 启动 next build 失败:", r.error.message);
+  process.exit(1);
+}
+
 process.exit(r.status ?? 1);