-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.ts
executable file
·51 lines (47 loc) · 1.32 KB
/
bundle.ts
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
#!/usr/bin/env node -r ts-node/register/transpile-only
/* eslint-disable no-console */
import * as esbuild from "esbuild";
import { inlineDedupedWorker } from "./src";
import yargs from "yargs";
import mkdirp from "mkdirp";
async function main() {
const argv = await yargs.options({
main: { type: "string", demand: true },
worker: { type: "string", demand: true },
outdir: { type: "string" },
"split-outdir": { type: "string" },
outfile: { type: "string" },
style: { type: "string", choices: ["eval", "closure"], default: "eval" },
minify: { type: "boolean", default: false },
}).argv;
if (argv.outdir) {
await mkdirp(argv.outdir);
}
if (argv.splitOutdir) {
await mkdirp(argv.splitOutdir);
}
await esbuild.build({
entryPoints: { main: argv.main, worker: argv.worker },
outdir: argv.outdir,
outfile: argv.outfile,
bundle: true,
write: !!(argv.outdir || argv.outfile),
splitting: true,
chunkNames: "shared",
format: "esm",
metafile: true,
sourcemap: "inline",
minify: argv.minify,
plugins: [
inlineDedupedWorker({
style: argv.style as "eval" | "closure",
createWorkerModule: "create-worker",
splitOutdir: argv.splitOutdir,
}),
],
});
}
main().catch((e) => {
console.error(e.message);
process.exit(1);
});