This package has been deprecated

Author message:

This module has moved and is now available at @rollup/plugin-wasm. Please update your dependencies. This version is no longer maintained.

rollup-plugin-wasm

3.0.0 • Public • Published

rollup-plugin-wasm

semantic-release

Rollup plugin for importing WebAssembly modules.

Use this Rollup plugin to import WebAssembly modules and bundle them as base64 strings. They are imported async (but small modules can be imported sync).

Install

npm i -D rollup-plugin-wasm

Configuration

Add the plugin to your rollup config and then any imported .wasm file will be processed by it.

import wasm from 'rollup-plugin-wasm'

export default {
  input: 'web/index.js',
  plugins: [
    wasm()
  ]
}

Example

Given the following simple C file (compiled using emscripten, or the online WasmFiddle tool):

int main() {
  return 42;
}

Import and instantiate the resulting file:

import wasm from './sample.wasm';

sample({ ...imports }).then(({ instance }) => {
  console.log(instance.exports.main())
})

The WebAssembly is inlined as a base64 encoded string (which means it will be ~33% larger than the original). At runtime the string is decoded and a module is returned.

Sync Modules

Small modules (< 4KB) can be compiled synchronously by specifying them in the configuration.

wasm({
  sync: [
    'web/sample.wasm',
    'web/foobar.wasm'
  ]
})

This means that the exports can be accessed immediately.

import module from './sample.wasm'

const instance = sample({ ...imports })

console.log(instance.exports.main())

Package Sidebar

Install

npm i rollup-plugin-wasm

Weekly Downloads

2

Version

3.0.0

License

MIT

Unpacked Size

4.25 kB

Total Files

3

Last publish

Collaborators

  • colineberhardt
  • jamen