Skip to content

Commit 40720ff

Browse files
committed
Patch wasm-pack bundler target for Cloudflare Workers
Following Cloudflare's documentation found here: https://developers.cloudflare.com/workers/languages/rust/#javascript-plumbing-wasm-bindgen Fixes #156
1 parent 2732736 commit 40720ff

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

minify-html-wasm/build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ if [[ "$target" = "bundler" ]]; then
1414
jq -s '.[0] * .[1]' package.json ../package.merge.json > package.new.json
1515
mv package.new.json package.json
1616
rm .gitignore
17+
# https://developers.cloudflare.com/workers/languages/rust/#javascript-plumbing-wasm-bindgen
18+
cp ../index.js index.js
1719
elif [[ "$target" = "web" ]]; then
1820
rm package.json .gitignore
1921
fi

minify-html-wasm/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as imports from "./index_bg.js"
2+
3+
// switch between both syntax for node and for workerd
4+
import wkmod from "./index_bg.wasm"
5+
import * as wasm from "./index_bg.wasm"
6+
if (typeof process !== "undefined" && process.release.name === "node") {
7+
imports.__wbg_set_wasm(wasm)
8+
} else {
9+
const instance = new WebAssembly.Instance(wkmod, { "./index_bg.js": imports })
10+
imports.__wbg_set_wasm(instance.exports)
11+
}
12+
13+
export * from "./index_bg.js"

0 commit comments

Comments
 (0)