kuboon_daily-nav/esbuild.config.ts
2026-04-04 00:31:40 +00:00

70 lines
1.6 KiB
TypeScript

/// <reference lib="deno.ns" />
import esbuild from "esbuild";
import builtins from "builtin-modules";
import { denoPlugin } from "@deno/esbuild-plugin";
const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;
const mode = Deno.args[0]; // "production" | "preview" | undefined (dev)
if (mode === "preview") {
const ctx = await esbuild.context({
plugins: [denoPlugin()],
entryPoints: ["ui/calendar-renderer.ts"],
bundle: true,
format: "esm",
target: "es2018",
logLevel: "info",
outdir: "ui",
});
const result = await ctx.serve({ servedir: ".", port: 3000 });
console.log(`Preview: http://localhost:${result.port}/ui/preview.html`);
// keeps running until Ctrl+C
await new Promise(() => {});
}
const prod = mode === "production";
const context = await esbuild.context({
plugins: [denoPlugin()],
banner: {
js: banner,
},
entryPoints: ["main.ts"],
bundle: true,
external: [
"obsidian",
"electron",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins,
],
format: "cjs",
target: "es2018",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
minify: prod,
});
if (prod) {
await context.rebuild();
Deno.exit(0);
} else {
await context.watch();
}