-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathesbuild.config.js
More file actions
109 lines (93 loc) · 2.63 KB
/
esbuild.config.js
File metadata and controls
109 lines (93 loc) · 2.63 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import * as esbuild from "esbuild";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
import { rmSync } from "fs";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const isProduction = process.env.NODE_ENV === "production";
// Shared build options
const sharedOptions = {
bundle: true,
platform: "node",
target: "node18",
format: "esm",
sourcemap: !isProduction,
minify: isProduction,
treeShaking: true,
metafile: true,
// External dependencies that should not be bundled
external: [
"node-pty", // Native module
"puppeteer", // Has its own bundled browser
"grammy", // Keep external for easier updates
"@ai-sdk/*", // AI SDK packages
"@google/genai", // Google AI
"archiver",
"dotenv",
"zod",
"ai",
],
logLevel: "info",
outExtension: { ".js": ".js" },
};
async function build() {
try {
// Clean dist folder before building
console.log("🧹 Cleaning dist folder...");
rmSync("dist", { recursive: true, force: true });
console.log(
`🔨 Building coderBOT (${
isProduction ? "production" : "development"
} mode)...`
);
// Build main app entry point
const appResult = await esbuild.build({
...sharedOptions,
entryPoints: ["src/app.ts"],
outfile: "dist/app.js",
});
// Build CLI entry point
const cliResult = await esbuild.build({
...sharedOptions,
entryPoints: ["src/cli.ts"],
outfile: "dist/cli.js",
});
// Build bot worker
const workerResult = await esbuild.build({
...sharedOptions,
entryPoints: ["src/bot-worker.ts"],
outfile: "dist/bot-worker.js",
});
console.log("✅ Build completed successfully!");
if (isProduction) {
console.log("\n📊 Bundle analysis:");
await analyzeBundle(appResult.metafile, "app.js");
await analyzeBundle(cliResult.metafile, "cli.js");
await analyzeBundle(workerResult.metafile, "bot-worker.js");
}
} catch (error) {
console.error("❌ Build failed:", error);
process.exit(1);
}
}
async function analyzeBundle(metafile, name) {
if (!metafile) return;
const analysis = await esbuild.analyzeMetafile(metafile, {
verbose: false,
});
console.log(`\n📦 ${name}:`);
console.log(analysis);
}
// Watch mode
if (process.argv.includes("--watch")) {
console.log("👀 Watching for changes...");
const ctx = await esbuild.context({
...sharedOptions,
entryPoints: ["src/app.ts", "src/cli.ts", "src/bot-worker.ts"],
outdir: "dist",
});
await ctx.watch();
console.log("Watching...");
} else {
build();
}