Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
vite-plugin-wasm
Advanced tools
Add WebAssembly ESM integration (aka. Webpack's `asyncWebAssembly`) to Vite and support `wasm-pack` generated modules.
Add WebAssembly ESM integration (aka. Webpack's asyncWebAssembly
) to Vite and support wasm-pack
generated modules.
Now this plugin supports both Vite 2.x and 3.x. Just install it:
yarn add -D vite-plugin-wasm
You also need the vite-plugin-top-level-await
plugin unless you target very modern browsers only (i.e. set build.target
to esnext
).
import wasm from "vite-plugin-wasm";
import topLevelAwait from "vite-plugin-top-level-await";
export default defineConfig({
plugins: [
wasm(),
topLevelAwait()
]
});
If you are getting ESBuild errors of WASM files (In the format No loader is configured for ".wasm" files: node_modules/somepackage/somefile.wasm
) with Vite < 3.0.3, please upgrade your Vite to >= 3.0.3 or upgrade this plugin to >= 3.1.0. A workaround is adding the corresponding imported module within node_modules
to optimizeDeps.exclude
, e.g.:
export default defineConfig({
optimizeDeps: {
exclude: [
"@syntect/wasm"
]
}
});
To use this plugin in Web Workers. Add it (and vite-plugin-top-level-await
if necessary) to worker.plugins
. To support Firefox, don't use ES workers. leave worker.format
default and use vite-plugin-top-level-await
>= 1.4.0 (see also here):
export default defineConfig({
plugins: [
wasm(),
topLevelAwait()
],
worker: {
// Not needed with vite-plugin-top-level-await >= 1.3.0
// format: "es",
plugins: [
wasm(),
topLevelAwait()
]
}
});
TypeScript typing is broken. Since we can't declare a module with Record<string, any>
as its named export map. Your import ... from "./module.wasm";
will still got Vite's bulit-in typing, but the transformed code is fine. So just use an asterisk import import * as wasmModule from "./module.wasm"
and type assertion (you have typing for your WASM files, right?).
FAQs
Add WebAssembly ESM integration (aka. Webpack's `asyncWebAssembly`) to Vite and support `wasm-pack` generated modules.
The npm package vite-plugin-wasm receives a total of 50,136 weekly downloads. As such, vite-plugin-wasm popularity was classified as popular.
We found that vite-plugin-wasm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.