-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.mjs
47 lines (41 loc) · 1008 Bytes
/
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
import esbuild from "esbuild";
const shouldWatch = process.env.DEV == "true";
const bundle = shouldWatch ? esbuild.context : esbuild.build;
const commonOptions = {
external: ["@aws-sdk/client-dynamodb", "@aws-sdk/util-dynamodb"],
target: "es6",
bundle: true,
minify: !process.env.DEV,
sourcemap: shouldWatch,
dropLabels: shouldWatch ? undefined : ["DEV"],
outdir: "dist",
entryPoints: ["src/index.ts"],
plugins: [
{
name: "watcher",
setup(build) {
const { format } = build.initialOptions;
build.onEnd(() => {
console.log(`Build ${format}`, new Date().toLocaleString());
});
},
},
],
};
const cjs = {
...commonOptions,
platform: "node",
format: "cjs",
};
const esm = {
...commonOptions,
platform: "node",
format: "esm",
outExtension: { ".js": ".mjs" },
};
const cjsContext = await bundle(cjs);
const esmContext = await bundle(esm);
if (shouldWatch) {
await cjsContext.watch();
await esmContext.watch();
}