This repository was archived by the owner on Nov 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.mjs
More file actions
48 lines (45 loc) · 1.18 KB
/
build.mjs
File metadata and controls
48 lines (45 loc) · 1.18 KB
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
import { execSync } from "child_process";
import esbuild from "esbuild";
import path from "path";
import { fileURLToPath } from "url";
import fs from "fs/promises";
const dirname = path.dirname(fileURLToPath(import.meta.url));
const options = {
bundle: true,
entryPoints: [path.join(dirname, "src/index.ts")],
minify: false,
outdir: path.join(dirname, "dist"),
platform: "node",
plugins: [{
name: "wasm",
setup(build) {
build.onLoad({ filter: /\.wasm$/ }, async (args) => ({
contents: await fs.readFile(args.path),
loader: "binary"
}));
}
}],
sourcemap: false,
target: "es6"
};
Promise.all([
esbuild.build({
...options,
format: "esm",
outExtension: { ".js": ".mjs" },
banner: {
js: `import { createRequire } from "module"; const require = createRequire(import.meta.url);`,
}
}),
esbuild.build({
...options,
format: "cjs",
outExtension: { ".js": ".cjs" }
})
]).then(([esm, cjs]) => {
// When we're done building the output, we'll want to additionally build the
// typescript declarations file.
if (esm.errors.length + cjs.errors.length === 0) {
execSync("./node_modules/.bin/tsc");
}
});