Skip to content

Commit

Permalink
update cloudflare README
Browse files Browse the repository at this point in the history
  • Loading branch information
justjake committed Jan 26, 2024
1 parent a80fdfd commit ab6c700
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 7 additions & 2 deletions examples/cloudflare-workers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@

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.

1. We need to copy the WASM files for the QuickJS variants in use into the `src` directory, so we can import them directly. See [copy-wasm-file-into-src.sh](./copy-wasm-file-into-src.sh).
2. We need to override the normal loading behavior to use the special imported WebAssembly.Module. See [src/index.mts](./src/index.mts).
1. 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](./copy-wasm-file-into-src.sh) does this. You should copy it to your project, and run it whenever you update `quickjs-emscripten` to a new version. It will copy the WASM and SourceMap files from `node_modules` into the src directory every time you run it.
- This creates the files `src/DEBUG_SYNC.wasm` and `src/DEBUG_SYNC.wasm.map.txt`. Add them to your .gitignore.
2. We need to override the normal loading behavior to use the special imported WebAssembly.Module. See [src/index.mts](./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()`, use `newQuickJSWASMModule(cloudflareVariant)`.
4 changes: 1 addition & 3 deletions examples/vite-vue/src/components/HelloWorld.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import type { QuickJSAsyncContext, QuickJSContext } from "quickjs-emscripten-cor
const vms = ref<Array<QuickJSContext | QuickJSAsyncContext>>([])
load().then((deps) => {
vms.value = [
deps.newContext()
]
vms.value = [deps.newContext()]
})
const code = ref("1 + 2")
Expand Down

0 comments on commit ab6c700

Please sign in to comment.