Skip to main content
FarmFarm
Version: 2.x (Latest)
On this page

@farmfe/plugin-wasm

A Rust Farm plugin for seamless WebAssembly integration, including support for wasm-pack generated modules.

Installation

javascript
npm install -D @farmfe/plugin-wasm
javascript
yarn add -D @farmfe/plugin-wasm
javascript
pnpm add -D @farmfe/plugin-wasm

Usage

Register the plugin in farm.config.ts:

ts
import { defineConfig } from "@farmfe/core";
import wasm from "@farmfe/plugin-wasm";

export default defineConfig({
  plugins: [wasm()],
});

Pre-compiled .wasm files can be imported with the ?init query. The default export is an initialization function:

ts
import init from "./example.wasm?init";

init().then((instance) => {
  instance.exports.test();
});

The initialization function can receive a WebAssembly import object:

ts
import init from "./example.wasm?init";

init({
  imports: {
    someFunc: () => {},
  },
});

WASM packages can also be imported as ESM modules:

ts
import { someFunc } from "wasm-project";

someFunc();

Options

This plugin does not expose user options.

100%

Drag or pinch to explore. Keyboard: + / − zoom, arrows pan, 0 resets, Esc closes.