Files
fangke/sdk/build.mjs
T

18 lines
684 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { build } from "esbuild";
import { execSync } from "node:child_process";
let buildId;
try {
buildId = execSync("git log -1 --format=%h-%cd --date=format:%Y%m%d%H%M").toString().trim();
} catch {
buildId = "dev-" + Date.now();
}
await build({
entryPoints: ["src/index.ts"], bundle: true, minify: true, format: "iife",
outfile: "dist/v1.js", target: ["es2020"], // 代码依赖 globalThis(es2018 目标名不副实)
// define 键必须用点链:esbuild 只做精确表达式匹配,裸键不会替换
// globalThis.__BUILD_ID__ 成员访问(实测 0.24.2),裸键将恒为 "unknown"
define: { "globalThis.__BUILD_ID__": JSON.stringify(buildId) },
});