-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.mjs
73 lines (66 loc) · 1.85 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
62
63
64
65
66
67
68
69
70
71
72
73
import esbuild from "esbuild";
import { execSync } from "child_process";
const shouldWatch = process.env.DEV == "true";
const compileDeclarations = () => {
try {
execSync("tsc");
} catch (error) {
console.log(error.output?.[1]?.toString());
}
};
const external = ["esbuild", "archiver", "serve-static", "@smithy/eventstream-codec", "local-aws-sqs", "@aws-sdk/client-sqs", "ajv", "ajv-formats", "fast-xml-parser"];
const watchPlugin = {
name: "watch-plugin",
setup: (build) => {
const format = build.initialOptions.format;
build.onEnd(async (result) => {
console.log("Build", format, new Date().toLocaleString());
compileDeclarations();
});
},
};
const esBuildConfig = {
bundle: true,
minify: !shouldWatch,
platform: "node",
target: "node18",
outdir: "dist",
plugins: [watchPlugin],
dropLabels: shouldWatch ? [] : ["DEV"],
drop: shouldWatch ? [] : ["debugger"],
external,
};
const bundle = shouldWatch ? esbuild.context : esbuild.build;
const buildIndex = bundle.bind(null, {
...esBuildConfig,
entryPoints: [
"./src/server.ts",
"./src/defineConfig.ts",
"./src/lib/runtime/runners/node/index.ts",
"./src/lambda/router.ts",
"./src/plugins/sns/index.ts",
"./src/plugins/sqs/index.ts",
"./src/plugins/s3/index.ts",
"./src/lambda/body-parser.ts",
],
format: "cjs",
});
const buildRouterESM = bundle.bind(null, {
...esBuildConfig,
entryPoints: [
"./src/index.ts",
"./src/server.ts",
"./src/defineConfig.ts",
"./src/lambda/router.ts",
"./src/plugins/sns/index.ts",
"./src/plugins/sqs/index.ts",
"./src/plugins/s3/index.ts",
"./src/lambda/body-parser.ts",
],
format: "esm",
outExtension: { ".js": ".mjs" },
});
const result = await Promise.all([buildIndex(), buildRouterESM()]);
if (shouldWatch) {
await Promise.all(result.map((x) => x.watch()));
}