chore: speedup wasm build

This commit is contained in:
Zixuan Chen 2023-03-23 22:19:26 +08:00
parent b0d7ad88b9
commit 85d91e10b4

View file

@ -32,6 +32,26 @@ async function build() {
return buildTarget(target);
}));
if (profile !== "dev") {
let first = true;
let firstTarget = "";
for (const target of TARGETS) {
if (first) {
const cmd =
`wasm-opt -O4 ${target}/loro_wasm_bg.wasm -o ${target}/loro_wasm_bg.wasm`;
console.log(">", cmd);
firstTarget = target;
await Deno.run({ cmd: cmd.split(" "), cwd: LoroWasmDir }).status();
first = false;
} else {
const cmd =
`cp ${firstTarget}/loro_wasm_bg.wasm ${target}/loro_wasm_bg.wasm`;
console.log(">", cmd);
await Deno.run({ cmd: cmd.split(" "), cwd: LoroWasmDir }).status();
}
}
}
console.log(
"✅",
"Build complete in",
@ -67,20 +87,11 @@ async function buildTarget(target: string) {
console.log("Clear directory " + targetDirPath);
} catch (e) {}
for (const cmd of genCommands(target)) {
const cmd =
`wasm-bindgen --weak-refs --target ${target} --out-dir ${target} ../../target/wasm32-unknown-unknown/${profileDir}/loro_wasm.wasm`;
console.log(">", cmd);
await Deno.run({ cmd: cmd.split(" "), cwd: LoroWasmDir }).status();
}
console.log();
}
function genCommands(target: string): string[] {
return [
`wasm-bindgen --weak-refs --target ${target} --out-dir ${target} ../../target/wasm32-unknown-unknown/${profileDir}/loro_wasm.wasm`,
...(profile == "dev" ? [] : [
`wasm-opt -O4 ${target}/loro_wasm_bg.wasm -o ${target}/loro_wasm_bg.wasm`,
]),
];
}
build();