-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
49 lines (40 loc) · 1.07 KB
/
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
49
// @ts-check
const { spawnSync } = require("child_process");
const esbuild = require("esbuild");
const glob = require("tiny-glob");
/**
* @param {esbuild.BuildOptions} baseOptions
* @param {esbuild.Format} format
*/
async function build(baseOptions, format) {
console.log(`🔨 ${format}`);
console.time(`✅ ${format} build time`);
await esbuild.build({
...baseOptions,
format,
outdir: `./dist/${format}`,
target: format === "esm" ? "es2018" : "es2015",
});
console.timeEnd(`✅ ${format} build time`);
}
function buildDts() {
console.log("🔨 .d.ts");
console.time("✅ .d.ts build time");
spawnSync("tsc", ["--emitDeclarationOnly"], {
stdio: "inherit",
});
console.timeEnd("✅ .d.ts build time");
}
(async () => {
const tsPaths = await glob("src/**/*.ts");
/** @type {esbuild.BuildOptions} */
const baseOptions = {
entryPoints: tsPaths,
platform: "node",
sourcemap: true,
};
console.log(`${tsPaths.length} files to build`);
await build(baseOptions, "esm");
await build(baseOptions, "cjs");
buildDts();
})();