mossy1022_Smart-Connections.../esbuild.config.mjs

77 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-05-29 15:58:31 +00:00
import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import dotenv from "dotenv";
dotenv.config();
import fs from "fs";
import path from "path";
2024-05-29 15:58:31 +00:00
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");
2024-05-31 16:06:06 +00:00
const copy_to_plugins = {
name: 'copy_to_plugins',
setup(build) {
build.onEnd(() => {
const plugin_path = path.join(process.env.OBSIDIAN_PLUGINS_PATH, "smart-connections-visualizer");
2024-05-30 14:29:30 +00:00
2024-05-31 16:06:06 +00:00
if (!fs.existsSync(plugin_path)) {
fs.mkdirSync(plugin_path);
}
2024-05-30 14:29:30 +00:00
2024-05-31 16:06:06 +00:00
fs.copyFileSync("./main.js", path.join(plugin_path, "main.js"));
fs.copyFileSync("./manifest.json", path.join(plugin_path, "manifest.json"));
fs.copyFileSync("./styles.css", path.join(plugin_path, "styles.css"));
// add empty .hotreload file
fs.writeFileSync(path.join(plugin_path, ".hotreload"), "");
2024-05-30 14:29:30 +00:00
2024-05-31 16:06:06 +00:00
console.log("Plugin built and copied to obsidian plugins folder");
});
}
};
2024-05-29 15:58:31 +00:00
const context = await esbuild.context({
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",
2024-05-30 14:29:30 +00:00
...builtins
],
2024-05-29 15:58:31 +00:00
format: "cjs",
target: "es2018",
logLevel: "info",
sourcemap: "inline",
2024-05-29 15:58:31 +00:00
treeShaking: true,
outfile: "main.js",
2024-05-30 14:29:30 +00:00
plugins: [
2024-05-31 16:06:06 +00:00
copy_to_plugins
2024-05-30 14:29:30 +00:00
]
2024-05-29 15:58:31 +00:00
});
2024-05-30 14:29:30 +00:00
if(!prod) await context.watch();
else {
2024-05-29 15:58:31 +00:00
await context.rebuild();
process.exit(0);
}