-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathesbuild.config.mjs
53 lines (49 loc) · 1.29 KB
/
esbuild.config.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
43
44
45
46
47
48
49
50
51
52
53
import obPlugin from "@aidenlx/esbuild-plugin-obsidian";
import { build, context } from "esbuild";
import { lessLoader } from "esbuild-plugin-less";
const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source visit the plugins github repository
*/
`;
const isProd = process.env.BUILD === "production";
const opts = {
entryPoints: ["src/fn-main.ts"],
bundle: true,
platform: "browser",
external: ["obsidian"],
format: "cjs",
mainFields: ["browser", "module", "main"],
banner: { js: banner },
sourcemap: isProd ? false : "inline",
minify: isProd,
define: {
"process.env.NODE_ENV": JSON.stringify(process.env.BUILD),
},
outfile: "build/main.js",
plugins: [
lessLoader({
javascriptEnabled: true,
}),
obPlugin(),
],
};
if (!isProd) {
const ctx = await context({ ...opts, logLevel: "error" });
try {
await ctx.watch();
} catch (err) {
console.error(err);
await cleanup();
}
process.on("SIGINT", cleanup);
// eslint-disable-next-line no-inner-declarations
async function cleanup() {
await ctx.dispose();
// scheduleOnDisposeCallbacks defer function calls using setTimeout(...,0)
// so we need to wait a bit before exiting
// setTimeout(() => process.exit(), 100);
}
} else {
await build(opts);
}