-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathesbuild.config.ts
More file actions
48 lines (42 loc) · 1.31 KB
/
Copy pathesbuild.config.ts
File metadata and controls
48 lines (42 loc) · 1.31 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
import esbuild from "esbuild";
import { createPluginBundlerPresets } from "@paperclipai/plugin-sdk/bundlers";
const presets = createPluginBundlerPresets({ uiEntry: "src/ui/index.tsx" });
const watch = process.argv.includes("--watch");
const { worker, manifest, ui } = presets.esbuild;
if (!worker || !manifest || !ui) {
throw new Error("Plugin bundler presets are missing required esbuild targets.");
}
function buildOptions(
options: esbuild.BuildOptions,
buildTarget: "manifest" | "ui" | "worker",
): esbuild.BuildOptions {
if (watch) return options;
return {
...options,
legalComments: "none",
minify: buildTarget !== "ui",
sourcemap: false,
};
}
const workerContext = await esbuild.context(buildOptions(worker, "worker"));
const manifestContext = await esbuild.context(buildOptions(manifest, "manifest"));
const uiContext = await esbuild.context(buildOptions(ui, "ui"));
if (watch) {
await Promise.all([
workerContext.watch(),
manifestContext.watch(),
uiContext.watch(),
]);
console.log("esbuild watch mode enabled for worker, manifest, and ui");
} else {
await Promise.all([
workerContext.rebuild(),
manifestContext.rebuild(),
uiContext.rebuild(),
]);
await Promise.all([
workerContext.dispose(),
manifestContext.dispose(),
uiContext.dispose(),
]);
}