Repository navigation
Expand file tree
/
Copy pathbuild.ts
More file actions
62 lines (55 loc) · 1.45 KB
/
Copy pathbuild.ts
File metadata and controls
62 lines (55 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { rm } from "node:fs/promises";
// Clean dist folder
await rm("./dist", { recursive: true, force: true });
// Build ESM
const esmResult = await Bun.build({
entrypoints: ["./src/index.ts"],
outdir: "./dist",
format: "esm",
target: "browser",
minify: true,
sourcemap: "external",
external: ["@bsv/sdk"],
naming: "[dir]/index.module.[ext]",
});
if (!esmResult.success) {
console.error("ESM build failed:");
for (const log of esmResult.logs) {
console.error(log);
}
process.exit(1);
}
// Build CJS
const cjsResult = await Bun.build({
entrypoints: ["./src/index.ts"],
outdir: "./dist",
format: "cjs",
target: "browser",
minify: true,
sourcemap: "external",
external: ["@bsv/sdk"],
naming: "[dir]/index.[ext]",
});
if (!cjsResult.success) {
console.error("CJS build failed:");
for (const log of cjsResult.logs) {
console.error(log);
}
process.exit(1);
}
// Rename CJS output from .js to .cjs
const cjsFile = Bun.file("./dist/index.js");
if (await cjsFile.exists()) {
await Bun.write("./dist/index.cjs", cjsFile);
await rm("./dist/index.js");
// Also rename sourcemap
const cjsMapFile = Bun.file("./dist/index.js.map");
if (await cjsMapFile.exists()) {
await Bun.write("./dist/index.cjs.map", cjsMapFile);
await rm("./dist/index.js.map");
}
}
console.log("Build complete!");
console.log(" - dist/index.module.js (ESM)");
console.log(" - dist/index.cjs (CommonJS)");
console.log("\nRun 'bun run types' to generate TypeScript declarations.");