-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.mjs
More file actions
46 lines (39 loc) · 981 Bytes
/
esbuild.mjs
File metadata and controls
46 lines (39 loc) · 981 Bytes
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
import esbuild from "esbuild"
import fs from "fs"
import { cssPlugin, graphqlPlugin } from "./plugins/esbuild.mjs"
const sharedConfig = {
entryPoints: ["src/main.ts"],
bundle: true,
minifyIdentifiers: true,
minifySyntax: true,
target: "es2020",
sourcemap: true,
plugins: [cssPlugin(), graphqlPlugin()]
}
async function build() {
try {
await esbuild.build({
...sharedConfig,
outfile: "dist/main.cjs.js",
format: "cjs"
})
await esbuild.build({
...sharedConfig,
outfile: "dist/main.es.js",
format: "esm"
})
const result = await esbuild.build({
...sharedConfig,
minifyWhitespace: true,
outfile: "dist/main.es.bundle.js",
format: "esm",
metafile: true
})
fs.writeFileSync("meta.json", JSON.stringify(result.metafile))
console.log("Build completed successfully.")
} catch (error) {
console.error("Build failed:", error)
process.exit(1)
}
}
await build()