logancyang_obsidian-copilot/esbuild.config.mjs

72 lines
1.7 KiB
JavaScript
Raw Normal View History

import esbuild from "esbuild";
2023-04-04 20:09:45 +00:00
import svgPlugin from "esbuild-plugin-svg";
import process from "process";
import wasmPlugin from "./wasmPlugin.mjs";
import nodeModuleShim from "./nodeModuleShim.mjs";
2023-03-31 00:15:32 +00:00
2024-08-21 22:16:22 +00:00
const banner = `/*
2023-03-31 00:15:32 +00:00
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
// Polyfill for import.meta in CommonJS context
if (typeof import_meta === 'undefined') {
var import_meta = {
url: typeof __filename !== 'undefined' ? 'file://' + __filename : 'file:///obsidian-plugin'
};
}
2023-03-31 00:15:32 +00:00
`;
2024-08-21 22:16:22 +00:00
const prod = process.argv[2] === "production";
2023-03-31 00:15:32 +00:00
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",
// Node.js built-in modules (available in Electron) - except node:module which we shim
"node:fs",
"node:path",
"node:url",
"node:buffer",
"node:stream",
"node:crypto",
"node:async_hooks",
2024-08-21 22:16:22 +00:00
],
format: "cjs",
target: "es2020",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
plugins: [nodeModuleShim, svgPlugin(), wasmPlugin],
define: {
global: "window",
2025-02-12 07:59:05 +00:00
"process.env.NODE_ENV": prod ? '"production"' : '"development"',
"import.meta.url": "import_meta.url",
},
2025-02-12 07:59:05 +00:00
minify: prod,
2023-03-31 00:15:32 +00:00
});
if (prod) {
await context.rebuild();
process.exit(0);
2023-03-31 00:15:32 +00:00
} else {
await context.watch();
2024-08-21 22:16:22 +00:00
}