-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.js
77 lines (70 loc) · 1.78 KB
/
build.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const esbuild = require("esbuild");
const { nodeExternalsPlugin } = require("esbuild-node-externals");
const { exec } = require("child_process");
// Function to run esbuild with given options
const build = async (options) => {
try {
await esbuild.build({
...options,
bundle: true,
minify: true,
platform: "neutral",
plugins: [nodeExternalsPlugin()],
});
console.log(`Build successful: ${options.outfile}`);
} catch {
process.exit(1);
}
};
// Build configurations for CJS and ESM
const buildOptions = [
{
entryPoints: ["src/index.ts"],
outfile: "dist/bundle.cjs.js",
format: "cjs",
},
{
entryPoints: ["src/index.ts"],
outfile: "dist/bundle.esm.js",
format: "esm",
},
];
// Execute builds
buildOptions.forEach(build);
// Generate type declarations
exec("tsc --emitDeclarationOnly --outDir dist", (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`TypeScript declarations generated: ${stdout}`);
if (stderr) {
console.error(`stderr: ${stderr}`);
}
});
// const esbuild = require("esbuild");
// const { nodeExternalsPlugin } = require("esbuild-node-externals");
// // Bundle CommonJS
// esbuild
// .build({
// entryPoints: ["src/index.js"],
// bundle: true,
// minify: true,
// platform: "neutral",
// outfile: "dist/bundle.cjs.js",
// format: "cjs",
// plugins: [nodeExternalsPlugin()],
// })
// .catch(() => process.exit(1));
// // Bundle ES Module
// esbuild
// .build({
// entryPoints: ["src/index.js"],
// bundle: true,
// minify: true,
// platform: "neutral",
// outfile: "dist/bundle.esm.js",
// format: "esm",
// plugins: [nodeExternalsPlugin()],
// })
// .catch(() => process.exit(1));