-
Notifications
You must be signed in to change notification settings - Fork 4
/
esbuild.mjs
42 lines (38 loc) · 1.19 KB
/
esbuild.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
// SOURCE: https://github.com/peterpeterparker/create-ic/blob/main/esbuild.mjs
import esbuild from "esbuild";
import { existsSync, mkdirSync, writeFileSync } from "fs";
import { join } from "path";
import NodeResolve from "@esbuild-plugins/node-resolve";
const dist = join(process.cwd(), "dist");
if (!existsSync(dist)) {
mkdirSync(dist);
}
const script = await esbuild.build({
entryPoints: ["src/index.ts"],
bundle: true,
minify: true,
platform: "node",
write: false,
plugins: [
NodeResolve.NodeResolvePlugin({
extensions: [".ts", ".js"],
onResolved: (resolved) => {
// We want all node modules in the same bundle.
// Except for the node-hid module which needs to be outside to work properly.
// There is another library with the name "hw-transport-node-hid-noevents"
// That's why need such a fine-grained check.
if (
resolved.includes("node_modules") &&
resolved.includes("node-hid") &&
!resolved.includes("noevents")
) {
return {
external: true,
};
}
return resolved;
},
}),
],
});
writeFileSync("dist/index.js", `${script.outputFiles[0].text}`);