Build frontend locally for lightweight deployment

This commit is contained in:
wuyanwanwu
2026-08-13 23:44:50 +08:00
parent d8aaf63e05
commit 6037bde760
26 changed files with 242 additions and 18 deletions
+32
View File
@@ -0,0 +1,32 @@
import { cpSync, existsSync, mkdirSync, rmSync } from "node:fs";
import { spawnSync } from "node:child_process";
import { join } from "node:path";
const root = process.cwd();
const distDir = join(root, "dist");
const clientDir = join(distDir, "client");
const outputDir = join(root, "out");
const vinextBin = join(root, "node_modules", ".bin", process.platform === "win32" ? "vinext.cmd" : "vinext");
rmSync(distDir, { recursive: true, force: true });
rmSync(outputDir, { recursive: true, force: true });
const result = spawnSync(vinextBin, ["build"], {
cwd: root,
stdio: "inherit",
shell: process.platform === "win32",
});
const builtIndex = join(clientDir, "index.html");
if (!existsSync(builtIndex)) {
console.error("\n本地构建失败:没有生成 dist/client/index.html。\n");
process.exit(result.status || 1);
}
mkdirSync(outputDir, { recursive: true });
cpSync(clientDir, outputDir, { recursive: true });
console.log("\n部署成品已生成:out/\n");
// vinext 1.0 beta can hit a Windows libuv assertion after a successful export.
// The fresh artifact check above is the source of truth for this browser-only site.
process.exit(0);