-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.mjs
52 lines (47 loc) · 1.33 KB
/
build.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
52
import { context } from "esbuild"
const watchFlag = process.argv[2] === "--watch"
;(async () => {
if (!watchFlag) {
console.log("Build...")
console.time("Build successfully")
}
await Promise.all(
[
// Web
{
id: "browser",
platform: "browser",
outfile: "dist/index-web.js",
},
// Node
{
id: "node-cjs",
format: "cjs",
outfile: "dist/index-node.cjs",
},
{
id: "node-mjs",
outfile: "dist/index-node.mjs",
},
].map(async ({ id, ...config }) => {
const ctx = await context({
entryPoints: ["src/index.ts"],
bundle: true,
minify: true,
sourcemap: true,
format: "esm",
platform: "node",
keepNames: true,
...config,
}).catch(() => process.exit(1))
if (watchFlag) {
console.log(`Watching "${id}" ...`)
await ctx.watch()
} else {
await ctx.rebuild()
await ctx.dispose()
}
})
)
!watchFlag && console.timeEnd("Build successfully")
})()