-
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathbuild.mjs
More file actions
48 lines (43 loc) · 1.25 KB
/
build.mjs
File metadata and controls
48 lines (43 loc) · 1.25 KB
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
import { build } from "esbuild";
import { copyFileSync } from "fs";
import { dirname, resolve } from "path";
import { fileURLToPath } from "url";
const rootDir = dirname(fileURLToPath(import.meta.url));
const entries = [
{ entry: "src/index.js", base: "index", globalName: "__tc" },
{ entry: "src/toggle.js", base: "toggle", globalName: "__tcToggle" },
{ entry: "src/btn.js", base: "btn", globalName: "__tcBtn" },
{ entry: "src/select.js", base: "select", globalName: "__tcSelect" },
];
await Promise.all(
entries.flatMap(({ entry, base, globalName }) => [
build({
entryPoints: [resolve(rootDir, entry)],
bundle: true,
format: "esm",
minify: true,
outfile: resolve(rootDir, `${base}.mjs`),
target: ["es2020"],
}),
build({
entryPoints: [resolve(rootDir, entry)],
bundle: true,
format: "iife",
globalName,
minify: true,
outfile: resolve(rootDir, `${base}.js`),
target: ["es2020"],
footer:
base === "index"
? {
js: "if(typeof window!=='undefined'){__tc.themeChange()}",
}
: undefined,
}),
]),
);
copyFileSync(
resolve(rootDir, "src/index.d.ts"),
resolve(rootDir, "index.d.ts"),
);
console.log("Build complete");