-
Notifications
You must be signed in to change notification settings - Fork 351
/
build.mjs
74 lines (64 loc) · 1.78 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
74
import esbuild from "esbuild";
import fs from "fs/promises";
import path from "path";
const OUTDIR = "build";
await fs.rm(OUTDIR, { recursive: true, force: true });
async function buildReact() {
const outbase = path.join(OUTDIR, "react");
const outfile = path.join(outbase, "index.mjs");
await fs.mkdir(outbase, { recursive: true });
await fs.copyFile("src/react/index.html", path.join(outbase, "index.html"));
const devMode = process.argv.slice(2)[0] == "--dev";
await esbuild.build({
entryPoints: {
index: "src/ssr.ts",
app: "src/react/index.tsx",
},
logLevel: "info",
...(!devMode && {
platform: "node",
}),
external: ["@aws-sdk"],
target: "es2023",
format: devMode ? "cjs" : "esm",
define: {
"process.env.NODE_ENV": JSON.stringify("production"),
},
loader: {
".svg": "file",
},
bundle: true,
outdir: outbase,
});
await fs.rename(path.join(outbase, "index.js"), outfile);
await fs.readFile(outfile).then((data) => {
const indexSource = `import { createRequire } from "module";\nconst require = createRequire(import.meta.url);\n${data.toString()}`;
return fs.writeFile(outfile, indexSource);
});
}
async function buildExternalSdkFunction() {
const outbase = path.join(OUTDIR, "external");
const outfile = path.join(outbase, "index.mjs");
await esbuild.build({
entryPoints: {
index: "src/non-included-sdk.mjs",
},
logLevel: "info",
platform: "browser",
target: "es2023",
format: "esm",
bundle: true,
minify: true,
sourcemap: false,
outfile,
external: [
"@smithy",
"@aws-sdk/core",
"@aws-sdk/util-user-agent-browser",
"@aws-crypto",
"bowser",
],
});
}
await buildReact();
await buildExternalSdkFunction();