-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.ts
70 lines (59 loc) · 1.9 KB
/
build.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import dts from "bun-plugin-dts";
import Logger from "@rabbit-company/logger";
import fs from "fs/promises";
await fs.rm("./browser", { recursive: true, force: true });
await fs.rm("./module", { recursive: true, force: true });
await fs.rm("./dist", { recursive: true, force: true });
Logger.info("Start bulding browser...");
let browserBuild = await Bun.build({
entrypoints: ["./src/argon2id.ts", "./src/argon2id_worker.ts"],
outdir: "./browser",
target: "browser",
format: "esm",
minify: {
identifiers: false,
syntax: true,
whitespace: true,
},
plugins: [],
});
await Bun.write(Bun.file("./browser/argon2id_wasm_bg.wasm"), Bun.file("./src/argon2id_wasm_bg.wasm"));
if (browserBuild.success) {
Logger.info("Bulding browser complete");
} else {
Logger.error("Bulding browser failed");
}
Logger.info("Start bulding module...");
let moduleBuild = await Bun.build({
entrypoints: ["./src/argon2id.ts", "./src/argon2id_worker.ts"],
outdir: "./module",
target: "browser",
format: "esm",
minify: false,
plugins: [dts({ output: { noBanner: true } })],
});
await Bun.write(Bun.file("./module/argon2id_wasm_bg.wasm"), Bun.file("./src/argon2id_wasm_bg.wasm"));
if (moduleBuild.success) {
Logger.info("Bulding module complete");
} else {
Logger.error("Bulding module failed");
}
fs.cp("./src/index.html", "./dist/index.html", { recursive: true, force: true });
Logger.info("Start bundling dist...");
let distBuild = await Bun.build({
entrypoints: ["./src/index.ts", "./src/argon2id_worker.ts"],
outdir: "./dist",
target: "browser",
format: "esm",
minify: true,
sourcemap: "none",
plugins: [],
});
await Bun.write(Bun.file("./dist/argon2id_wasm_bg.wasm"), Bun.file("./src/argon2id_wasm_bg.wasm"));
await Bun.write(Bun.file("./dist/index.html"), Bun.file("./src/index.html"));
if (distBuild.success) {
Logger.info("Bundling dist complete");
} else {
Logger.error("Bundling dist failed");
Logger.error(distBuild.logs);
}