-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.mts
60 lines (56 loc) · 1.29 KB
/
build.mts
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
import fs from "fs";
import path from "path";
import glob from "fast-glob";
import { build, BuildOptions } from "esbuild";
const entryPoints = [];
const srcdir = path.resolve("src");
const outdir = path.resolve("dist");
const files = glob.stream(["**", "!*.d.ts", "!**/__tests__"], {
cwd: srcdir,
}) as AsyncIterable<string>;
for await (const file of files) {
if (path.extname(file) === ".ts") {
entryPoints.push(path.resolve(srcdir, file));
} else {
const outfile = path.join(outdir, file);
await fs.promises.mkdir(path.dirname(outfile), { recursive: true });
await fs.promises.copyFile(path.join(srcdir, file), outfile);
}
}
const opts: BuildOptions = {
outdir,
entryPoints,
outbase: srcdir,
platform: "node",
target: ["es2019"],
define: {
"process.env.NODE_ENV": "'production'",
},
};
await Promise.all([
build({
...opts,
format: "cjs",
}),
build({
...opts,
format: "esm",
bundle: true,
splitting: true,
outExtension: { ".js": ".mjs" },
plugins: [
{
name: "external-modules",
setup(build) {
build.onResolve(
{ filter: /^[^./]|^\.[^./]|^\.\.[^/]/ },
({ path }) => ({
path,
external: true,
})
);
},
},
],
}),
]);