-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.mjs
52 lines (51 loc) · 1.41 KB
/
esbuild.mjs
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
import * as esbuild from 'esbuild'
import child_process from "child_process";
let start = Date.now();
function buildDts(entryPoints, dir) {
// try {
// child_process.execSync(`npx tsc ${entryPoints.join(" ")} --declaration --emitDeclarationOnly --outDir ${dir}`);
// } catch (e) { }
/// output
try {
let result = child_process.execSync(`npx tsc ${entryPoints.join(" ")} --declaration --emitDeclarationOnly --outDir ${dir}`);
console.log(result.toString("utf-8"));
} catch (e) {
console.log(e.stdout.toString("utf-8"));
}
}
const entryPoints = [
"src/index.ts",
"src/components.tsx"
];
const defaults = {
minify: true,
outdir: "dist/",
platform: "browser",
treeShaking: true,
}
async function build(opt) {
for (let i = 0; i < entryPoints.length; i++) {
await esbuild.build({
entryPoints: [entryPoints[i]],
...defaults,
...opt,
bundle: i==0,
external: i==0?["preact","."]:undefined,
})
}
}
console.log("Building CommonJS");
await build({
format: "cjs",
outdir: "dist/cjs",
});
console.log("Building ESM");
await build({
format: "esm",
outdir: "dist/esm",
});
console.log("Building CommonJS DTS")
buildDts(entryPoints, "dist/");
buildDts(entryPoints, "dist/esm"); // for jsr
console.log("built dts")
console.log("Build Complete in " + (Date.now() - start) + "ms")