mirror of
https://github.com/nellowtcs/Obsidian-IroView.git
synced 2026-07-22 06:56:57 +00:00
67 lines
1.4 KiB
JavaScript
67 lines
1.4 KiB
JavaScript
import esbuild from "esbuild";
|
|
import process from "process";
|
|
import builtins from "builtin-modules";
|
|
import fs from "fs/promises";
|
|
import path from "path";
|
|
|
|
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";
|
|
|
|
// Helper function to copy files
|
|
async function copyFile(src, destDir) {
|
|
const dest = path.join(destDir, path.basename(src));
|
|
await fs.mkdir(destDir, { recursive: true });
|
|
await fs.copyFile(src, dest);
|
|
console.log(`Copied ${src} -> ${dest}`);
|
|
}
|
|
|
|
// esbuild setup
|
|
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,
|
|
outfile: "./dist/main.js",
|
|
minify: prod,
|
|
});
|
|
|
|
async function copyAssets() {
|
|
await copyFile("src/styles.css", "dist");
|
|
await copyFile("manifest.json", "dist");
|
|
}
|
|
|
|
if (prod) {
|
|
await context.rebuild();
|
|
await copyAssets();
|
|
process.exit(0);
|
|
} else {
|
|
await context.watch();
|
|
await copyAssets();
|
|
}
|