-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathesbuild.mjs
More file actions
49 lines (44 loc) · 1.03 KB
/
esbuild.mjs
File metadata and controls
49 lines (44 loc) · 1.03 KB
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
import * as esbuild from "esbuild";
let define = {};
const KEYS_TO_DEFINE = [
"ENV",
"SENTRY_DSN",
"SENTRY_ORG",
"SENTRY_PROJECT",
"SENTRY_DSN",
];
if (process.env.ENV === "production") {
for (const k of KEYS_TO_DEFINE) {
define[`process.env.${k}`] = JSON.stringify(process.env[k]);
}
}
/**
* @type {esbuild.BuildOptions}
*/
const config = {
entryPoints: ["lib/ditto.ts"],
bundle: true,
metafile: true,
keepNames: true,
tsconfig: "tsconfig.json",
sourcemap: process.env.ENV === "production" ? "external" : "both",
minify: process.env.ENV === "production",
outdir: "bin",
target: "es2020",
packages: "external",
platform: "node",
define,
};
async function main() {
const result = await esbuild.build(config);
// Output build metafile so we can analyze the bundle
// size over time and check if anything unexpected is being bundled in.
if (process.env.ENV === "production") {
console.log(
await esbuild.analyzeMetafile(result.metafile, {
verbose: true,
})
);
}
}
main();