vite-plugin-assemblyscript

1.0.3 • Public • Published

vite-plugin-assemblyscript

Simple assemblyscript plugin for vite.

This will compile all your imported as file into a base64 string, and will replace imported AS file with :

const binaryString = atob("${source.toString('base64')}");
const bytes = new Uint8Array(binaryString.length);
for (var i = 0; i < binaryString.length; i++) {
    bytes[i] = binaryString.charCodeAt(i);
}
const module = await WebAssembly.instantiate(bytes.buffer, {});
export const wasmBinary = bytes.buffer
export default module.instance.exports

Which means that you can use AS files like this :

// file: add.as
//@ts-ignore
export function add(a: i32, b: i32): i32 {
  return a + b;
}
  import wasmAdd from './add.as'
  console.log(wasmAdd.add(2, 3))

/vite-plugin-assemblyscript/

    Package Sidebar

    Install

    npm i vite-plugin-assemblyscript

    Weekly Downloads

    4

    Version

    1.0.3

    License

    MIT

    Unpacked Size

    4.51 kB

    Total Files

    4

    Last publish

    Collaborators

    • olivierchatry