### Installing unwasm Package with Various Package Managers Source: https://github.com/unjs/unwasm/blob/main/README.md Provides commands for installing the unwasm npm package using different package managers, including nypm, npm, yarn, pnpm, and bun. ```sh npx nypm install unwasm ``` ```sh npm install unwasm ``` ```sh yarn add unwasm ``` ```sh pnpm install unwasm ``` ```sh bun install unwasm ``` ```sh deno install unwasm ``` -------------------------------- ### Parse WebAssembly Binary with unwasm/tools Source: https://github.com/unjs/unwasm/blob/main/README.md Demonstrates how to use the `parseWasm` function from `unwasm/tools` to read and parse a WebAssembly binary file, providing structured information about its exports and imports. The example also shows the typical JSON output structure. ```JavaScript import { readFile } from "node:fs/promises"; import { parseWasm } from "unwasm/tools"; const source = await readFile(new URL("examples/sum.wasm", import.meta.url)); const parsed = parseWasm(source); console.log(JSON.stringify(parsed, undefined, 2)); ``` ```JSON { "modules": [ { "exports": [ { "id": 5, "name": "rand", "type": "Func" }, { "id": 0, "name": "memory", "type": "Memory" } ], "imports": [ { "module": "env", "name": "seed", "params": [], "returnType": "f64" } ] } ] } ``` -------------------------------- ### Importing WebAssembly Files as WebAssembly.Module Instances in JavaScript Source: https://github.com/unjs/unwasm/blob/main/README.md Demonstrates how to import a .wasm file directly as a WebAssembly.Module instance using the ?module suffix, which is useful for libraries that handle WebAssembly.Instance instantiation themselves. ```js import _sumMod from "unwasm/examples/sum.wasm?module"; const { sum } = await WebAssembly.instantiate(_sumMod).then((i) => i.exports); ``` -------------------------------- ### unwasm Plugin Configuration Options Source: https://github.com/unjs/unwasm/blob/main/README.md Details the available configuration options for unwasm plugins, including `esmImport` for direct WASM file imports and `lazy` for lazy evaluation of WASM modules. ```APIDOC Plugin Options: esmImport: boolean (default: false) Directly import the wasm file instead of bundling. Required in Cloudflare Workers and works with environments that allow natively importing a .wasm module. lazy: boolean (default: false) Import .wasm files using a lazily evaluated proxy for compatibility with runtimes without top-level await support. ``` -------------------------------- ### Importing WebAssembly Modules Statically in JavaScript Source: https://github.com/unjs/unwasm/blob/main/README.md Demonstrates how to import a .wasm module like a standard ES Module import when the target environment supports top-level await and the module requires no explicit imports object. ```js import { sum } from "unwasm/examples/sum.wasm"; ``` -------------------------------- ### Dynamically Importing WebAssembly Modules with Custom Imports in JavaScript Source: https://github.com/unjs/unwasm/blob/main/README.md Illustrates how to dynamically import and initialize a .wasm module that requires an import object, passing the necessary environment variables for its execution. ```js const { rand } = await import("unwasm/examples/rand.wasm").then((r) => r.default({ env: { seed: () => () => Math.random() * Date.now(), }, }), ); ``` -------------------------------- ### Statically Importing and Initializing WebAssembly Modules with Custom Imports in JavaScript Source: https://github.com/unjs/unwasm/blob/main/README.md Explains how to use static import for a .wasm module that requires an import object, initializing it separately with the required environment after the initial import. ```js import initRand, { rand } from "unwasm/examples/rand.wasm"; await initRand({ env: { seed: () => () => Math.random() * Date.now(), }, }); ``` -------------------------------- ### Importing WebAssembly Modules Dynamically in JavaScript Source: https://github.com/unjs/unwasm/blob/main/README.md Shows how to dynamically import a .wasm module using await import(), suitable when top-level await is available and the module does not require an imports object. ```js const { sum } = await import("unwasm/examples/sum.wasm"); ``` -------------------------------- ### Configure Auto Imports in package.json for unwasm Source: https://github.com/unjs/unwasm/blob/main/README.md Illustrates how to define `exports` and `imports` in a `package.json` file to hint to the bundler how to resolve imports needed by `.wasm` files, enabling automatic bundling via import maps. ```JSON { "exports": { "./rand.wasm": "./rand.wasm" }, "imports": { "env": "./env.mjs" } } ``` -------------------------------- ### Integrating unwasm Rollup Plugin for WebAssembly Transformation Source: https://github.com/unjs/unwasm/blob/main/README.md Shows how to configure the unwasm plugin within a rollup.config.js file, enabling it to transform .wasm imports during the build process for compatibility. ```js // rollup.config.js import { rollup as unwasm } from "unwasm/plugin"; export default { plugins: [ unwasm({ /* options */ }), ], }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.