-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
37 lines (33 loc) · 860 Bytes
/
build.ts
File metadata and controls
37 lines (33 loc) · 860 Bytes
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
import fs from "node:fs";
import path from "node:path";
import esbuild from "esbuild";
import type { Format, BuildOptions } from "esbuild";
const entryPoints = fs
.readdirSync("src")
.filter((f) => !f.endsWith(".test.ts"))
.map((f) => path.resolve("src", f));
async function build(format: Exclude<Format, "iife">): Promise<void> {
const outdir = `dist/${format}`;
const options: BuildOptions = {
target: ["esnext"],
format,
platform: "node",
entryPoints,
outdir,
treeShaking: true,
sourcemap: "inline",
};
const result = await esbuild.build(options);
for (const error of result.errors) {
console.error(error.text);
}
for (const warning of result.warnings) {
console.warn(warning.text);
}
if (result.errors.length !== 0) {
process.exit(1);
}
process.exit(0);
}
build("esm");
build("cjs");