-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
30 lines (27 loc) · 809 Bytes
/
esbuild.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
const { build, analyzeMetafile } = require("esbuild");
const fs = require("node:fs");
const pkg = require("./package.json");
appBuild = async () => {
try {
const result = await build({
entryPoints: ["src/**/*.ts"],
outdir: "dist",
minify: true,
platform: "node",
format: "cjs",
treeShaking: true,
bundle: true,
metafile: true,
external: [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]
});
if (result.metafile) {
fs.writeFileSync("./dist/metafile.json", JSON.stringify(result.metafile));
}
console.log("Build successful:", await analyzeMetafile(result.metafile));
process.exit(0);
} catch (error) {
console.error("Build failed:", error);
process.exit(1);
}
};
appBuild();