basant307/AI_Governance_Project
048
1esbuild-plugin-wasm2===================3 4An asynchronous `.wasm` file loader for [esbuild](https://esbuild.github.io/). This allows you to directly import `.wasm` files as if they were a javascript module, similar to how it works in Webpack.5 6This plugin follows the [WebAssembly/ES Module Integration](https://github.com/WebAssembly/esm-integration) proposal for loading WebAssembly from a JavaScript import statement.7 8## Requirements9- esbuild >= 0.11.010- node >= 10.0.011 12### ⚠️ Important Note ⚠️13 14This loader makes use of top-level await, which only has partial support in esbuild. For now, it is only supported with the `esm` output format, not the `iife` or `cjs` formats. See https://github.com/evanw/esbuild/issues/25315 16## Installation17 18```19npm install --save-dev esbuild-plugin-wasm20```21 22or23 24```25yarn add --dev esbuild-plugin-wasm26```27 28## Usage291. Add it to your esbuild plugins list30 31 <details>32 <summary>CommonJS</summary>33 34 ```js35 // build.js36 const esbuild = require('esbuild')37 const { wasmLoader } = require('esbuild-plugin-wasm')38 39 esbuild.build({40 ...41 plugins: [42 wasmLoader()43 ]44 ...45 });46 ```47 48 </details>49 50 <details>51 <summary>ESM</summary>52 53 ```js54 // build.js55 import esbuild from 'esbuild'56 import { wasmLoader } from 'esbuild-plugin-wasm'57 58 esbuild.build({59 ...60 plugins: [61 wasmLoader()62 ]63 ...64 });65 ```66 67 </details>68 69 <details>70 <summary>Typescript</summary>71 72 ```ts73 // build.ts74 import esbuild from 'esbuild'75 import { wasmLoader } from 'esbuild-plugin-wasm'76 77 esbuild.build({78 ...79 plugins: [80 wasmLoader()81 ]82 ...83 });84 ```85 86 </details>87 88 892. Then import ad use your wasm in your project90 91 92 <details>93 <summary>CommonJS</summary>94 95 ```js96 // app.js97 const wasm = require("./lib.wasm");98 99 console(wasm.add(1, 2));100 ```101 102 </details>103 104 <details>105 <summary>ESM</summary>106 107 ```js108 // app.js109 import wasm from "./lib.wasm";110 111 console(wasm.add(1, 2));112 ```113 114 </details>115 116 <details>117 <summary>Typescript</summary>118 119 ```ts120 // app.ts121 import wasm from "./lib.wasm";122 123 console(wasm.add(1, 2));124 ```125 126 </details>127 128 129## Configuration130 131```ts132wasmLoader({133 // (Default) Deferred mode copies the WASM binary to the output directory,134 // and then `fetch()`s it at runtime. This is the default mode.135 mode: 'deferred'136 137 // Embedded mode embeds the WASM binary in the javascript bundle as a138 // base64 string. Note this will greatly bloat the resulting bundle139 // (the binary will take up about 30% more space this way)140 mode: 'embedded'141})142```143 