-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
47 lines (41 loc) · 1.16 KB
/
build.js
File metadata and controls
47 lines (41 loc) · 1.16 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
const { build } = require("esbuild");
const { copyFile } = require("fs/promises");
const { resolve } = require("path");
const baseOptions = {
entryPoints: ["./src/index.ts"],
platform: "node",
target: "es2018",
bundle: true,
external: ["@glideapps/ts-necessities"],
};
async function buildPackage() {
try {
// Build ESM version
await build({
...baseOptions,
outfile: "./dist/index.mjs",
format: "esm",
});
// Build CommonJS version
await build({
...baseOptions,
outfile: "./dist/index.js",
format: "cjs",
});
// Copy the TypeScript declarations
await copyFile(
resolve("./dist/index.d.ts"),
resolve("./dist/index.d.mts")
).catch((err) => {
// Ignore if the file doesn't exist, as TypeScript doesn't generate .d.mts files
if (err.code !== "ENOENT") {
throw err;
}
});
console.log("✅ Build completed");
} catch (err) {
console.error("❌ Build failed:", err);
process.exit(1);
}
}
buildPackage();