-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add non-included SDK sample * remove comment
- Loading branch information
1 parent
716e40d
commit e67efd7
Showing
14 changed files
with
1,607 additions
and
966 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,74 @@ | ||
import esbuild from "esbuild"; | ||
import fs from "fs/promises"; | ||
import path from "path"; | ||
|
||
const OUTDIR = "build"; | ||
const OUT_JS_INDEX = `${OUTDIR}/index.mjs`; | ||
|
||
await fs.rm(OUTDIR, { recursive: true, force: true }); | ||
await fs.mkdir(OUTDIR); | ||
await fs.copyFile("src/react/index.html", `${OUTDIR}/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: "es2020", | ||
format: devMode ? "cjs" : "esm", | ||
define: { | ||
"process.env.NODE_ENV": JSON.stringify("production"), | ||
}, | ||
loader: { | ||
".svg": "file", | ||
}, | ||
bundle: true, | ||
outdir: OUTDIR, | ||
}); | ||
|
||
await fs.rename(`${OUTDIR}/index.js`, OUT_JS_INDEX); | ||
await fs.readFile(OUT_JS_INDEX).then((data) => { | ||
const indexSource = `import { createRequire } from "module";\nconst require = createRequire(import.meta.url);\n${data.toString()}`; | ||
return fs.writeFile(OUT_JS_INDEX, indexSource); | ||
}); | ||
|
||
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: "es2020", | ||
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: "es2020", | ||
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.