quickjs-emscripten-core
This package is part of quickjs-emscripten, a Javascript interface for QuickJS compiled to WebAssembly via Emscripten.
This package (quickjs-emscripten-core
) contains only Javascript code - no WebAssembly. To use this package, you'll need to install one or more variants of the QuickJS WebAssembly build, see available variants below.
import { newQuickJSWASMModuleFromVariant } from "quickjs-emscripten-core"
import releaseVariant from "@jitl/quickjs-browser-release-sync-singlefile"
const QuickJS = await newQuickJSWASMModuleFromVariant(releaseVariant)
What's a variant?
A variant describes how to load a QuickJS WebAssembly build and how to call the low-level C API functions used by the higher-level abstractions in quickjs-emscripten-core
. A variant is an object with the following properties:
const variant = {
type: "sync",
importFFI: () => import("something/ffi.ts").then((mod) => mod.QuickJSFFI),
importModuleLoader: () => import("something/emscripten-module.ts"),
}
You can provide your own variant to control exactly how the large WebAssembly object is loaded. quickjs-emscripten-core
will call your variant's importXYZ methods during newQuickJSWASMModuleFromVariant
or newQuickJSAsyncWASMModuleFromVariant
.
Environment-specific variants
You can use subpath imports in package.json to select the appropriate variant for a runtime. This is how the main quickjs-emscripten
package picks between browser, Node ESM and Node CommonJS variants.
{
"imports": {
"#my-quickjs-variant": {
"types": "@jitl/quickjs-browser-release-sync-wasm",
"browser": "@jitl/quickjs-browser-release-sync-wasm",
"import": "@jitl/quickjs-node-esm-release-sync-wasm",
"require": "@jitl/quickjs-node-cjs-release-sync-wasm"
}
}
}
import { newQuickJSWASMModuleFromVariant } from "quickjs-emscripten-core"
import variant from "#my-quickjs-variant"
const QuickJS = await newQuickJSWASMModuleFromVariant(variant)
Available variants
Variant with separate .WASM file. Supports browser, NodeJS ESM, and NodeJS CJS.
Variable | Setting | Description |
---|
releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
emscriptenInclusion | wasm | Has a separate .wasm file. May offer better caching in your browser, and reduces the size of your JS bundle. If you have issues, try a 'singlefile' variant. |
exports | require import browser | Has these package.json export conditions |
Variant with separate .WASM file. Supports browser, NodeJS ESM, and NodeJS CJS.
Variable | Setting | Description |
---|
releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. Larger and slower. Allows synchronous calls from the WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! |
emscriptenInclusion | wasm | Has a separate .wasm file. May offer better caching in your browser, and reduces the size of your JS bundle. If you have issues, try a 'singlefile' variant. |
exports | require import browser | Has these package.json export conditions |
Variant with separate .WASM file. Supports browser, NodeJS ESM, and NodeJS CJS.
Variable | Setting | Description |
---|
releaseMode | release | Optimized for performance; use when building/deploying your application. |
syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
emscriptenInclusion | wasm | Has a separate .wasm file. May offer better caching in your browser, and reduces the size of your JS bundle. If you have issues, try a 'singlefile' variant. |
exports | require import browser | Has these package.json export conditions |
Variant with separate .WASM file. Supports browser, NodeJS ESM, and NodeJS CJS.
Variable | Setting | Description |
---|
releaseMode | release | Optimized for performance; use when building/deploying your application. |
syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. Larger and slower. Allows synchronous calls from the WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! |
emscriptenInclusion | wasm | Has a separate .wasm file. May offer better caching in your browser, and reduces the size of your JS bundle. If you have issues, try a 'singlefile' variant. |
exports | require import browser | Has these package.json export conditions |
Variant with the WASM data embedded into a NodeJS CommonJS module.
Variable | Setting | Description |
---|
releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
exports | require | Has these package.json export conditions |
Variant with the WASM data embedded into a NodeJS CommonJS module.
Variable | Setting | Description |
---|
releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. Larger and slower. Allows synchronous calls from the WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! |
emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
exports | require | Has these package.json export conditions |
Variant with the WASM data embedded into a NodeJS CommonJS module.
Variable | Setting | Description |
---|
releaseMode | release | Optimized for performance; use when building/deploying your application. |
syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
exports | require | Has these package.json export conditions |
Variant with the WASM data embedded into a NodeJS CommonJS module.
Variable | Setting | Description |
---|
releaseMode | release | Optimized for performance; use when building/deploying your application. |
syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. Larger and slower. Allows synchronous calls from the WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! |
emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
exports | require | Has these package.json export conditions |
Variant with the WASM data embedded into a NodeJS ESModule.
Variable | Setting | Description |
---|
releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
exports | import | Has these package.json export conditions |
Variant with the WASM data embedded into a NodeJS ESModule.
Variable | Setting | Description |
---|
releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. Larger and slower. Allows synchronous calls from the WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! |
emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
exports | import | Has these package.json export conditions |
Variant with the WASM data embedded into a NodeJS ESModule.
Variable | Setting | Description |
---|
releaseMode | release | Optimized for performance; use when building/deploying your application. |
syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
exports | import | Has these package.json export conditions |
Variant with the WASM data embedded into a NodeJS ESModule.
Variable | Setting | Description |
---|
releaseMode | release | Optimized for performance; use when building/deploying your application. |
syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. Larger and slower. Allows synchronous calls from the WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! |
emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
exports | import | Has these package.json export conditions |
Variant with the WASM data embedded into a browser ESModule.
Variable | Setting | Description |
---|
releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
exports | browser | Has these package.json export conditions |
Variant with the WASM data embedded into a browser ESModule.
Variable | Setting | Description |
---|
releaseMode | debug | Enables assertions and memory sanitizers. Try to run your tests against debug variants, in addition to your preferred production variant, to catch more bugs. |
syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. Larger and slower. Allows synchronous calls from the WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! |
emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
exports | browser | Has these package.json export conditions |
Variant with the WASM data embedded into a browser ESModule.
Variable | Setting | Description |
---|
releaseMode | release | Optimized for performance; use when building/deploying your application. |
syncMode | sync | The default, normal build. Note that both variants support regular async functions. |
emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
exports | browser | Has these package.json export conditions |
Variant with the WASM data embedded into a browser ESModule.
Variable | Setting | Description |
---|
releaseMode | release | Optimized for performance; use when building/deploying your application. |
syncMode | asyncify | Build run through the ASYNCIFY WebAssembly transform. Larger and slower. Allows synchronous calls from the WASM runtime to async functions on the host. The extra magic makes this variant slower than sync variants. Note that both variants support regular async functions. Only adopt ASYNCIFY if you need to! |
emscriptenInclusion | singlefile | The WASM runtime is included directly in the JS file. Use if you run into issues with missing .wasm files when building or deploying your app. |
exports | browser | Has these package.json export conditions |