You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The main `quickjs-emscripten` package includes several build variants of the WebAssembly module:
523
+
524
+
-`RELEASE...` build variants should be used in production. They offer better performance and smaller file size compared to `DEBUG...` build variants.
525
+
-`RELEASE_SYNC`: This is the default variant used when you don't explicitly provide one. It offers the fastest performance and smallest file size.
526
+
-`RELEASE_ASYNC`: The default variant if you need [asyncify][] magic, which comes at a performance cost. See the asyncify docs for details.
527
+
-`DEBUG...` build variants can be helpful during development and testing. They include source maps and assertions for catching bugs in your code. We recommend running your tests with _both_ a debug build variant and the release build variant you'll use in production.
528
+
-`DEBUG_SYNC`: Instrumented to detect memory leaks, in addition to assertions and source maps.
529
+
-`DEBUG_ASYNC`: An [asyncify][] variant with source maps.
530
+
531
+
To use a variant, call `newQuickJSWASMModule` or `newQuickJSAsyncWASMModule` with the variant object. These functions return a promise that resolves to a [QuickJSWASMModule](./doc/quickjs-emscripten/classes/QuickJSWASMModule.md), the same as `getQuickJS`.
const result =vm.unwrapResult(vm.evalCode("1 + 1")).consume(vm.getNumber)
556
+
console.log(result)
557
+
vm.dispose()
558
+
quickjs.dispose()
559
+
}
560
+
```
561
+
562
+
#### Reducing package size
563
+
564
+
Including 4 different copies of the WebAssembly module in the main package gives it an install size of [about 9.04mb](https://packagephobia.com/result?p=quickjs-emscripten). If you're building a CLI package or library of your own, or otherwise don't need to include 4 different variants in your `node_modules`, you can switch to the `quickjs-emscripten-core` package, which contains only the Javascript code for this library, and install one (or more) variants a-la-carte as separate packages.
565
+
566
+
The most minimal setup would be to install `quickjs-emscripten-core` and `@jitl/quickjs-wasmfile-release-sync` (1.3mb total):
To run QuickJS, we need to load a WebAssembly module into the host Javascript runtime's memory (usually as an ArrayBuffer or TypedArray) and [compile it](https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/instantiate_static) to a [WebAssembly.Module](https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Module). This means we need to find the file path or URI of the WebAssembly module, and then read it using an API like `fetch` (browser) or `fs.readFile` (NodeJS). `quickjs-emscripten` tries to handle this automatically using patterns like `new URL('./local-path', import.meta.url)` that work in the browser or are handled automatically by bundlers, or `__dirname` in NodeJS, but you may need to configure this manually if these don't work in your environment, or you want more control about how the WebAssembly module is loaded.
597
+
598
+
To customize the loading of an existing variant, create a new variant with your loading settings using `newVariant`, passing [CustomizeVariantOptions][newVariant]. For example, you need to customize loading in Cloudflare Workers (see [the full example][cloudflare]).
`quickjs-emscripten` and related packages should work in any environment that supports ES2020.
605
691
606
-
- NodeJS: requires v16.0.0 or later for WebAssembly compatibility. Tested with node@18.
607
-
- We estimate support for the following browsers:
692
+
- Browsers: we estimate support for the following browser versions. See the [global-iife][iife] and [esmodule][esm-html] HTML examples.
608
693
- Chrome 63+
609
694
- Edge 79+
610
695
- Safari 11.1+
611
696
- Firefox 58+
697
+
- NodeJS: requires v16.0.0 or later for WebAssembly compatibility. Tested with node@18. See the [node-typescript][tsx-example] and [node-minimal][minimal] examples.
0 commit comments