obsidian-logfire/esbuild.config.mjs
tolvitty 4d31129090 Projekt-Grundgerüst: Build-System und Konfiguration
package.json mit better-sqlite3, tsconfig (strict, ES2022),
esbuild mit native-module-resolver für better-sqlite3,
manifest.json (Desktop-only), leere styles.css.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 10:45:43 +01:00

67 lines
1.7 KiB
JavaScript

import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
const prod = process.argv[2] === "production";
// Rewrite bare "better-sqlite3" require to resolve via Obsidian's vault path.
// __dirname is Electron's internal asar path, not the plugin dir, so we use
// the global `app` object to construct the absolute path at runtime.
const nativeModulePlugin = {
name: "native-module-resolver",
setup(build) {
build.onResolve({ filter: /^better-sqlite3$/ }, () => ({
path: "better-sqlite3",
namespace: "native-module",
}));
build.onLoad({ filter: /.*/, namespace: "native-module" }, () => ({
contents: `
const path = require("path");
const pluginDir = path.join(
app.vault.adapter.basePath,
app.vault.configDir,
"plugins",
"logfire"
);
module.exports = require(path.join(pluginDir, "node_modules", "better-sqlite3"));
`,
loader: "js",
}));
},
};
const context = await esbuild.context({
entryPoints: ["src/main.ts"],
bundle: true,
plugins: [nativeModulePlugin],
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: "es2022",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
minify: prod,
});
if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}