forked from Vencord/venniepoints
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mjs
50 lines (45 loc) · 1.37 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
import esbuild from "esbuild";
import { readdir } from "fs/promises";
/**
* @type {esbuild.Plugin}
*/
const makeAllPackagesExternalPlugin = {
name: "make-all-packages-external",
setup(build) {
const filter = /^[^./]|^\.[^./]|^\.\.[^/]/; // Must not start with "/" or "./" or "../"
build.onResolve({ filter }, args => ({ path: args.path, external: true }));
},
};
/**
* @type {(namespace: string) => esbuild.Plugin}
*/
const includeDirPlugin = namespace => ({
name: `include-dir-plugin:${namespace}`,
setup(build) {
const filter = new RegExp(`^~${namespace}$`);
const dir = `./src/${namespace}`;
build.onResolve(
{ filter },
args => ({ path: args.path, namespace })
);
build.onLoad({ filter, namespace }, async () => {
const files = await readdir(dir);
return {
contents: files.map(f => `import "./${f.replace(".ts", "")}"`).join("\n"),
resolveDir: dir
};
});
}
});
await esbuild.build({
entryPoints: ["src/index.ts"],
bundle: true,
plugins: [includeDirPlugin("commands"), includeDirPlugin("modules"), makeAllPackagesExternalPlugin],
outfile: "dist/index.js",
minify: false,
treeShaking: true,
target: "esnext",
platform: "node",
sourcemap: "linked",
logLevel: "info"
});