generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
42 lines (37 loc) · 1.05 KB
/
esbuild.config.mjs
File metadata and controls
42 lines (37 loc) · 1.05 KB
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 esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import postCssPlugin from "esbuild-plugin-postcss2";
import { writeFile } from "fs/promises";
const prod = process.argv[2] === "production";
const context = await esbuild.context({
entryPoints: ["src/main.ts"],
bundle: true,
external: ["obsidian", "electron", ...builtins],
format: "cjs",
target: "es2018",
logLevel: "info",
sourcemap: "inline",
sourcesContent: !prod,
treeShaking: true,
outfile: "build/main.js",
});
if (prod) {
context.rebuild().catch(() => process.exit(1));
context.dispose();
} else {
context.watch().catch(() => process.exit(1));
}
// Separate processing for CSS output
const cssContext = await esbuild.context({
entryPoints: ["src/ui/styles.css"],
bundle: true,
outfile: "styles.css",
plugins: [postCssPlugin.default()],
});
if (prod) {
cssContext.rebuild().catch(() => process.exit(1));
cssContext.dispose();
} else {
cssContext.watch().catch(() => process.exit(1));
}