-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
48 lines (43 loc) · 1013 Bytes
/
build.js
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
const esbuild = require("esbuild");
const { exec } = require("child_process");
const fs = require("fs");
const path = require("path");
const entryPoints = ["./src/index.ts"];
const outDir = "dist";
// Clean the dist directory
if (fs.existsSync(outDir)) {
fs.rmSync(outDir, { recursive: true });
}
// CommonJS build
esbuild
.build({
entryPoints,
outdir: path.join(outDir, "cjs"),
bundle: true,
platform: "node",
target: ["node14"],
format: "cjs",
sourcemap: true,
})
.catch(() => process.exit(1));
// ESM build
esbuild
.build({
entryPoints,
outdir: path.join(outDir, "mjs"),
bundle: true,
platform: "node",
target: ["node14"],
format: "esm",
sourcemap: true,
})
.catch(() => process.exit(1));
// Type definitions
exec("tsc --emitDeclarationOnly --outDir dist/types", (err, stdout, stderr) => {
if (err) {
console.error(`Error generating type definitions: ${stderr}`);
process.exit(1);
} else {
console.log(stdout);
}
});