-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.js
More file actions
34 lines (30 loc) · 821 Bytes
/
bundle.js
File metadata and controls
34 lines (30 loc) · 821 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
import { build } from "esbuild";
import { minify } from "terser";
import fs from "node:fs";
async function bundle() {
// 1. Basic lib.js
await build({
entryPoints: ["src/main.ts"],
outfile: "dist/src-js/lib.js",
bundle: true,
format: "esm",
sourcemap: true,
});
// 2. Full bundle (could include all dependencies)
await build({
entryPoints: ["src/main.ts"],
outfile: "dist/src-js/lib.full.js",
bundle: true,
format: "esm",
sourcemap: true,
minify: false,
});
// 3. Minified version
const js = fs.readFileSync("dist/src-js/lib.full.js", "utf-8");
const minified = await minify(js, { sourceMap: { filename: "lib-min.js" } });
fs.writeFileSync("dist/src-js/lib-min.js", minified.code);
}
bundle().catch(err => {
console.error(err);
process.exit(1);
});