generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.esbuild.mjs
42 lines (35 loc) · 1.97 KB
/
.esbuild.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { appendFileSync } from "node:fs";
import builtins from "builtin-modules";
import esbuild from "esbuild";
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 production = process.argv[2] === "production";
const analyze = process.argv[2] === "analyze";
//──────────────────────────────────────────────────────────────────────────────
const result = await esbuild
.build({
entryPoints: ["src/main.ts"],
banner: { js: banner + "\n" },
outfile: "main.js",
bundle: true,
// biome-ignore format: no need to inspect this regularly
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: "es2022",
sourcemap: production || analyze ? false : "inline",
minify: production || analyze,
drop: ["debugger"],
treeShaking: true,
logLevel: analyze ? "silent" : "info",
metafile: analyze,
})
.catch(() => process.exit(1));
//──────────────────────────────────────────────────────────────────────────────
// DOCS https://esbuild.github.io/api/index#metafile
if (result.metafile) {
const sizes = await esbuild.analyzeMetafile(result.metafile, { verbose: false });
console.info(sizes);
}
// FIX prevent Obsidian from removing the source map when using dev build
// https://forum.obsidian.md/t/source-map-trimming-in-dev-builds/87612
if (!production) appendFileSync(import.meta.dirname + "/main.js", "\n/* nosourcemap */");