Skip to content

Commit

Permalink
feat(es/typescript): Add esm build for fast ts strip
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Jul 19, 2024
1 parent eb83471 commit 4136a64
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bindings/binding_typescript_wasm/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ wasm-pack build --out-name wasm --release --scope=swc --target nodejs
ls -al ./pkg

node ./scripts/patch.mjs

# esm
wasm-pack build --out-name wasm --out-dir pkg/esm --release --scope=swc --target web
node ./scripts/esm.mjs
26 changes: 26 additions & 0 deletions bindings/binding_typescript_wasm/scripts/esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import fs from "node:fs/promises";

await Promise.all([
fs.rename("pkg/esm/wasm_bg.wasm", "pkg/wasm_bg.wasm"),
fs.rename("pkg/esm/wasm.js", "pkg/wasm.mjs"),
fs.rename("pkg/esm/wasm.d.ts", "pkg/wasm.d.mts"),
]);

const pkgJsonFile = await fs.readFile("pkg/package.json", "utf8");
const pkgJson = JSON.parse(pkgJsonFile);
pkgJson.files.push("wasm_bg.wasm", "wasm.mjs", "wasm.d.mts");
pkgJson.exports = {
import: {
types: "./wasm.d.mts",
default: "./wasm.mjs",
},
default: {
types: "./wasm.d.ts",
default: "./wasm.js",
},
};

await Promise.all([
fs.rm("pkg/esm", { recursive: true, force: true }),
fs.writeFile("pkg/package.json", JSON.stringify(pkgJson, null, 2)),
]);

0 comments on commit 4136a64

Please sign in to comment.