-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.mjs
62 lines (55 loc) · 1.4 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
54
55
56
57
58
59
60
61
62
import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import {sassPlugin} from "esbuild-sass-plugin";
import * as fs from "fs/promises";
const banner =
"/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD see https://github.com/BambusControl/obsidian-substitutions for the source */";
const prodBuild = (process.argv[2] === "production");
const sourceDir = "./src/substitutions";
const outputDir = "./dist/substitutions";
/* Copy the manifest for working*/
await fs.mkdir(outputDir, {recursive: true});
await fs.copyFile("manifest.json", `${outputDir}/manifest.json`);
const buildOptions = {
banner: {
js: banner,
},
entryPoints: [
`${sourceDir}/main.ts`,
`${sourceDir}/styles.scss`,
],
entryNames: "[name]",
outdir: outputDir,
bundle: true,
external: [
"obsidian",
/* Every codemirror import must be listed. */
"@codemirror/state",
"@codemirror/view",
"@codemirror/language",
...builtins,
],
format: "cjs",
target: "ES6",
logLevel: "info",
sourcemap: prodBuild ? false : "inline",
treeShaking: true,
minify: prodBuild,
plugins: [
sassPlugin({
syntax: "scss",
style: prodBuild ? "compressed" : "expanded",
}),
],
dropLabels: prodBuild ? ["DEVELOPMENT"] : []
};
try {
if (prodBuild) {
await esbuild.build(buildOptions);
} else {
await (await esbuild.context(buildOptions)).watch();
}
} catch {
process.exit(1);
}