mirror of
https://github.com/ccmdi/obsidian-map-plus.git
synced 2026-07-22 06:43:14 +00:00
74 lines
2 KiB
JavaScript
74 lines
2 KiB
JavaScript
import esbuild from "esbuild";
|
|
import process from "process";
|
|
import { builtinModules } from "node:module";
|
|
|
|
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");
|
|
|
|
// Strip debug/dynamic script loading utilities from luma.gl and loaders.gl.
|
|
// These create <script> elements that trigger Obsidian's static analysis scanner.
|
|
// None are called by this plugin.
|
|
const stripDynamicScriptsPlugin = {
|
|
name: "strip-dynamic-scripts",
|
|
setup(build) {
|
|
// luma.gl: debug-only SpectorJS / WebGL dev tools loader
|
|
build.onLoad({ filter: /load-script\.[jt]s$/ }, () => ({
|
|
contents: "export async function loadScript() { throw new Error('not available'); }",
|
|
loader: "ts",
|
|
}));
|
|
// loaders.gl: dynamic library loader that injects script elements
|
|
build.onLoad({ filter: /library-utils\.[jt]s$/ }, async (args) => {
|
|
const fs = await import("fs");
|
|
let contents = fs.readFileSync(args.path, "utf8");
|
|
contents = contents.replace(
|
|
/const script = document\.createElement\(['"]script['"]\);[\s\S]*?document\.body\.appendChild\(script\);\s*return null;/,
|
|
"return null;",
|
|
);
|
|
return { contents, loader: "ts" };
|
|
});
|
|
},
|
|
};
|
|
|
|
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",
|
|
...builtinModules],
|
|
format: "cjs",
|
|
target: "es2020",
|
|
logLevel: "info",
|
|
sourcemap: prod ? false : "inline",
|
|
treeShaking: true,
|
|
plugins: [stripDynamicScriptsPlugin],
|
|
outfile: "main.js",
|
|
minify: prod,
|
|
});
|
|
|
|
if (prod) {
|
|
await context.rebuild();
|
|
process.exit(0);
|
|
} else {
|
|
await context.watch();
|
|
}
|