generated from moonlight-mod/sample-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.mjs
61 lines (51 loc) · 1.25 KB
/
build.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
import * as esbuild from "esbuild";
import copyStaticFiles from "esbuild-copy-static-files";
import fs from "fs";
const prod = process.env.NODE_ENV === "production";
const watch = process.argv.includes("--watch");
function makeConfig(ext, name) {
const entryPoints = [];
const fileExts = ["js", "jsx", "ts", "tsx"];
for (const fileExt of fileExts) {
const path = `./src/${ext}/${name}.${fileExt}`;
if (fs.existsSync(path)) entryPoints.push(path);
}
if (entryPoints.length === 0) return null;
return {
entryPoints,
outfile: `./dist/${ext}/${name}.js`,
format: "cjs",
platform: "node",
treeShaking: true,
bundle: true,
minify: prod,
sourcemap: "inline",
plugins: [
copyStaticFiles({
src: `./src/${ext}/manifest.json`,
dest: `./dist/${ext}/manifest.json`
})
]
};
}
const exts = fs.readdirSync("./src");
const config = exts
.map((x) => [
makeConfig(x, "index"),
makeConfig(x, "node"),
makeConfig(x, "host")
])
.flat()
.filter((c) => c !== null);
if (watch) {
await Promise.all(
config.map(async (c) => {
const ctx = await esbuild.context(c);
await ctx.watch();
})
);
} else {
for (const c of config) {
await esbuild.build(c);
}
}