mirror of
https://github.com/decaf-dev/obsidian-vault-explorer.git
synced 2026-07-22 10:10:31 +00:00
77 lines
1.6 KiB
JavaScript
77 lines
1.6 KiB
JavaScript
import builtins from "builtin-modules";
|
|
import esbuild from "esbuild";
|
|
import esbuildSvelte from "esbuild-svelte";
|
|
import fs from "fs";
|
|
import path from "path";
|
|
import process from "process";
|
|
import { sveltePreprocess } from "svelte-preprocess";
|
|
|
|
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";
|
|
|
|
const rebuildPlugin = {
|
|
name: "rebuild-handler",
|
|
setup(build) {
|
|
build.onEnd(async () => {
|
|
try {
|
|
await fs.promises.rename(
|
|
path.join(path.resolve(), "dist", "main.css"),
|
|
path.join(path.resolve(), "dist", "styles.css")
|
|
);
|
|
await fs.promises.copyFile(
|
|
path.join(path.resolve(), "manifest.json"),
|
|
path.join(path.resolve(), "dist", "manifest.json")
|
|
);
|
|
} catch (err) {}
|
|
});
|
|
}
|
|
};
|
|
|
|
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",
|
|
plugins: [
|
|
rebuildPlugin,
|
|
esbuildSvelte({
|
|
compilerOptions: { css: "external" },
|
|
preprocess: sveltePreprocess()
|
|
})
|
|
]
|
|
});
|
|
|
|
if (prod) {
|
|
await context.rebuild();
|
|
process.exit(0);
|
|
} else {
|
|
await context.watch();
|
|
}
|