mssoftjp_obsidian-voice-input/esbuild.config.mjs
2026-05-17 22:40:27 +09:00

62 lines
1.5 KiB
JavaScript

import esbuild from "esbuild";
import process from "process";
import { builtinModules } from "node:module";
import fs from "fs";
import path from "path";
const builtins = [...new Set(builtinModules.flatMap((name) => (
name.startsWith("node:") ? [name] : [name, `node:${name}`]
)))];
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 prod = (process.argv[2] === "production");
// Ensure build/latest exists as the output directory
const outDir = path.join(process.cwd(), "build", "latest");
fs.mkdirSync(outDir, { recursive: true });
const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ["src/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,
// Production builds must be minified (Obsidian dev docs: Optimize plugin load time)
minify: prod,
// Remove all other comments; banner remains
legalComments: 'none',
outfile: path.join(outDir, "main.js"),
});
if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}