Skip to content

Commit

Permalink
Patch wasm-pack bundler target for Cloudflare Workers
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarscher committed May 8, 2024
1 parent 2732736 commit f3accb6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions minify-html-wasm/build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ if [[ "$target" = "bundler" ]]; then
jq -s '.[0] * .[1]' package.json ../package.merge.json > package.new.json
mv package.new.json package.json
rm .gitignore
# https://developers.cloudflare.com/workers/languages/rust/#javascript-plumbing-wasm-bindgen
cp ../index.cloudflare.js index.js
elif [[ "$target" = "web" ]]; then
rm package.json .gitignore
fi
Expand Down
13 changes: 13 additions & 0 deletions minify-html-wasm/index.cloudflare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as imports from "./index_bg.js"

// switch between both syntax for node and for workerd
import wkmod from "./index_bg.wasm"
import * as wasm from "./index_bg.wasm"
if (typeof process !== "undefined" && process.release.name === "node") {
imports.__wbg_set_wasm(wasm)
} else {
const instance = new WebAssembly.Instance(wkmod, { "./index_bg.js": imports })
imports.__wbg_set_wasm(instance.exports)
}

export * from "./index_bg.js"

0 comments on commit f3accb6

Please sign in to comment.