-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ts
55 lines (44 loc) · 1.38 KB
/
build.ts
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
"use strict";
import * as fs from "node:fs";
import * as path from "node:path";
import { buildSync } from "esbuild";
import { globSync } from "glob";
import { cloneDeep } from "lodash";
const outputDir = path.resolve(__dirname, "dist");
const builder = __filename.replace(/\.js$/, ".ts");
const config = {
allowOverwrite: true,
platform: "node",
target: "esnext",
sourcemap: true,
sourcesContent: false,
write: true,
};
fs.rmSync(outputDir, { recursive: true });
console.log("Transpiling to CommonJS...");
// @ts-expect-error format should be assignable
// prettier-ignore
buildSync(Object.assign(cloneDeep(config), {
entryPoints: [builder],
format: "cjs",
outdir: __dirname,
}));
// @ts-expect-error format should be assignable
// prettier-ignore
buildSync(Object.assign(cloneDeep(config), {
entryPoints: globSync(["src/**/*.ts"]),
format: "cjs",
outdir: path.join(outputDir, "cjs"),
tsconfig: path.resolve(__dirname, "tsconfig.cjs.json"),
}));
console.log("Transpiling to ES Module...");
// @ts-expect-error format should be assignable
// prettier-ignore
buildSync(Object.assign(cloneDeep(config), {
entryPoints: globSync(["src/*.ts"]),
format: "esm",
outExtension: { ".js": ".mjs" },
outdir: path.join(outputDir, "esm"),
tsconfig: path.resolve(__dirname, "tsconfig.esm.json"),
}));
console.log("Successfully built files!");