-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.mjs
74 lines (66 loc) · 1.66 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 { buildSync } from "esbuild";
import { readdirSync, rmSync } from "fs";
/** @type {import('esbuild').BuildOptions} */
const DEFAULT_OPTIONS = {
target: "esnext",
bundle: true,
entryPoints: ["./src/index.ts", "./src/worker/index.ts"],
packages: "external",
keepNames: true,
minifyWhitespace: true,
minifyIdentifiers: true,
treeShaking: true,
drop: ["console", "debugger"],
outdir: "dist",
outbase: "src",
minifySyntax: true,
minify: true,
};
try {
rmSync("./dist", { recursive: true });
} catch {}
function buildWeb() {
/** @type {import('esbuild').BuildOptions} */
const OPTS = {
treeShaking: true,
splitting: true,
format: "esm",
platform: "browser",
outbase: "src",
external: ["worker_threads"],
outdir: "dist/browser",
};
const o = Object.assign({}, DEFAULT_OPTIONS, OPTS);
buildSync(o);
}
function buildNodeCJS() {
/** @type {import('esbuild').BuildOptions} */
const OPTS = {
treeShaking: true,
format: "cjs",
outExtension: { ".js": ".cjs" },
platform: "node",
outbase: "src",
outdir: "dist",
inject: ["./src/internals/NodeWorker-cjs.js", "./src/threads/channel-cjs.js"],
tsconfig: "./tsconfig.node.json",
};
const o = Object.assign({}, DEFAULT_OPTIONS, OPTS);
buildSync(o);
}
function buildNodeESM() {
/** @type {import('esbuild').BuildOptions} */
const OPTS = {
treeShaking: true,
format: "esm",
outExtension: { ".js": ".mjs" },
outbase: "src",
outdir: "dist",
splitting: true,
platform: "node",
inject: ["./src/internals/NodeWorker-esm.mjs", "./src/threads/channel-esm.mjs"],
};
const o = Object.assign({}, DEFAULT_OPTIONS, OPTS);
buildSync(o);
}
[buildNodeESM, buildNodeCJS, buildWeb].forEach((f) => f());