-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use with wrangler by cloudflare #156
Comments
AFAIK Wrangler is a Cloudflare CLI for Workers. Can you clarify what you are looking to do? If you want to use this library from a Worker, I believe you'll need the WASM variant, as I don't think the Workers runtime supports native Node.js modules. |
I was able to get The index.js created by wasm-bindgen needs to be patched. I edited node_modules/@minify-html/wasm/index.js to be this: 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" And then I could import and use the minify function normally from my project. import { minify } from "@minify-html/wasm"
const html = "<p>\n Some HTML\n</p>\n\n\n"
const encoder = new TextEncoder()
const decoder = new TextDecoder()
decoder.decode(
minify(encoder.encode(html), {
keep_spaces_between_attributes: true,
keep_comments: true,
}),
) This section of the cloudflare docs mentions that workaround. https://developers.cloudflare.com/workers/languages/rust/#javascript-plumbing-wasm-bindgen |
You may create PR for that, so we can use the wasm variant directly for workers without patch first. |
Following Cloudflare's documentation found here: https://developers.cloudflare.com/workers/languages/rust/#javascript-plumbing-wasm-bindgen Fixes wilsonzlin#156
Following Cloudflare's documentation found here: https://developers.cloudflare.com/workers/languages/rust/#javascript-plumbing-wasm-bindgen Fixes wilsonzlin#156
How to use with wrangler ?
The text was updated successfully, but these errors were encountered: