MCPcopy Create free account
hub / github.com/awslabs/llrt / buildReact

Function buildReact

example/functions/build.mjs:9–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7await fs.rm(OUTDIR, { recursive: true, force: true });
8
9async function buildReact() {
10 const outbase = path.join(OUTDIR, "react");
11 const outfile = path.join(outbase, "index.mjs");
12
13 await fs.mkdir(outbase, { recursive: true });
14 await fs.copyFile("src/react/index.html", path.join(outbase, "index.html"));
15
16 const devMode = process.argv.slice(2)[0] == "--dev";
17
18 await esbuild.build({
19 entryPoints: {
20 index: "src/ssr.ts",
21 app: "src/react/index.tsx",
22 },
23 logLevel: "info",
24 ...(!devMode && {
25 platform: "node",
26 }),
27 external: ["@aws-sdk"],
28 target: "es2023",
29 format: devMode ? "cjs" : "esm",
30 define: {
31 "process.env.NODE_ENV": JSON.stringify("production"),
32 },
33 loader: {
34 ".svg": "file",
35 },
36 bundle: true,
37 outdir: outbase,
38 });
39
40 await fs.rename(path.join(outbase, "index.js"), outfile);
41 await fs.readFile(outfile).then((data) => {
42 const indexSource = `import { createRequire } from "node:module";\nconst require = createRequire(import.meta.url);\n${data.toString()}`;
43 return fs.writeFile(outfile, indexSource);
44 });
45}
46
47async function buildExternalSdkFunction() {
48 const outbase = path.join(OUTDIR, "external");

Callers 1

build.mjsFile · 0.85

Calls 4

joinMethod · 0.80
toStringMethod · 0.65
sliceMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected