-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
52 lines (46 loc) · 1.38 KB
/
esbuild.config.mjs
File metadata and controls
52 lines (46 loc) · 1.38 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
43
44
45
46
47
48
49
50
51
52
import builtins from "builtin-modules";
import console from "console";
import esbuild from "esbuild";
import fs from "fs";
import path from "path";
import process from "process";
const prod = process.argv[2] === "production";
const moveToRootPlugin = {
name: "move-to-root",
setup(build) {
build.onEnd((_) => {
const cssFile = path.join("build", "main.css");
const targetFile = "styles.css";
if (fs.existsSync(cssFile)) {
let contents = fs.readFileSync(cssFile, "utf8");
// Remove source map comment
contents = contents.replace(/\/\*#\s*sourceMappingURL=.*?\*\/\s*$/s, "");
fs.writeFileSync(targetFile, contents);
fs.rmSync(cssFile);
console.log(`✓ CSS bundled to ${targetFile}`);
}
});
},
};
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",
loader: {
".css": "css",
},
plugins: [moveToRootPlugin],
});
if (prod) {
context.rebuild().catch(() => process.exit(1));
context.dispose();
} else {
context.watch().catch(() => process.exit(1));
}