Cloudflare Workers need some extra setup steps because of the unusual environment and limitations with the bundling defaults, because Cloudflare refuses to let us read these files and compile them from bytes.
- We need to copy the WASM files for the QuickJS variants in use into the
src
directory, so we can import them directly. The script copy-wasm-file-into-src.sh does this. You should copy it to your project, and run it whenever you updatequickjs-emscripten
to a new version. It will copy the WASM and SourceMap files fromnode_modules
into the src directory every time you run it.- This creates the files
src/DEBUG_SYNC.wasm
andsrc/DEBUG_SYNC.wasm.map.txt
. Add them to your .gitignore.
- This creates the files
- We need to override the normal loading behavior to use the special imported WebAssembly.Module. See src/index.mts. Copy and paste the code in index.mts into your project, or do something similar:
- import the quickjs-emscripten WASM files directly, like
import wasmModule from './DEBUG_SYNC.wasm'
. - import the quickjs-emscripten SourceMap.txt files directly as well, like
import wasmSourceMapData from './DEBUG_SYNC.wasm.map.txt'
. - create a new variant using those files:
const cloudflareVariant = newVariant(DEBUG_SYNC, { wasmModule, wasmSourceMapData })
. - Instead of using
await getQuickJS()
, usenewQuickJSWASMModule(cloudflareVariant)
.
- import the quickjs-emscripten WASM files directly, like