poanse_obsidian-taskmap/esbuild.config.mjs

73 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

import esbuild from "esbuild";
import process from "process";
2025-12-17 08:38:04 +00:00
import esbuildSvelte from "esbuild-svelte";
import { sveltePreprocess } from "svelte-preprocess";
import fs from "fs";
2025-12-17 08:38:04 +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
*/
`;
2025-12-17 08:38:04 +00:00
const prod = process.argv[2] === "production";
// Simple plugin to rename main.css to styles.css
const renameStyles = {
name: "rename-styles",
setup(build) {
build.onEnd(() => {
if (fs.existsSync("main.css")) {
fs.renameSync("main.css", "styles.css");
}
});
},
};
2023-01-25 18:49:50 +00:00
const context = await esbuild.context({
2025-12-17 08:38:04 +00:00
plugins: [
esbuildSvelte({
compilerOptions: {
css: "external",
2025-12-17 08:38:04 +00:00
},
preprocess: sveltePreprocess(),
}),
renameStyles,
2025-12-17 08:38:04 +00:00
],
banner: {
js: banner,
},
2025-12-17 08:38:04 +00:00
entryPoints: ["src/main.ts"],
bundle: true,
external: [
2023-01-25 18:49:50 +00:00
"obsidian",
"electron",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
2025-12-17 08:38:04 +00:00
],
2023-01-25 18:49:50 +00:00
format: "cjs",
2025-12-17 08:38:04 +00:00
target: "es2022",
logLevel: "info",
2023-01-25 18:49:50 +00:00
sourcemap: prod ? false : "inline",
treeShaking: true,
2023-01-25 18:49:50 +00:00
outfile: "main.js",
2023-11-15 19:10:43 +00:00
minify: prod,
pure: prod ? ["console.debug"] : [],
2023-01-25 18:49:50 +00:00
});
if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
2023-11-15 19:10:43 +00:00
}