Latest commit 7a3296f Mar 26, 2017 @ballercat committed on GitHub Merge pull request #1 from danieluhl/fix_typos
updates grammar in readme
Failed to load latest commit information.
.gitignore clean-up Mar 16, 2017
LICENSE License Mar 16, 2017 updates grammar in readme Mar 26, 2017
index.js clean-up Mar 16, 2017
output.js clean-up Mar 16, 2017
package.json fix typo in readme, bump version Mar 16, 2017

WASM Binary Module loader for Webpack

A simple .wasm binary file loader for Webpack. Import your wasm modules directly into your bundle as Constructors which return WebAssembly.Instance. This avoids the need to use fetch and parse for your wasm files. Imported wasm files are converted to Uint8Arrays and become part of the full JS bundle!


Install package: npm install --save wasm-loader


Edit webpack.config.js:

  loaders: [
      test: /\.wasm$/,
      loaders: ['wasm-loader']

Include wasm from your code:

import Counter from 'wasm/counter';

const counter = new Counter();
console.log(counter.exports.count()); // 0
console.log(counter.exports.count()); // 1
console.log(counter.exports.count()); // 2

The default export from wasm module is a constructor which returns a WebAssembly.Instance. deps can be passed in to override defaults. For example

const customCounter = new Counter({
  'global': {},
  'env': {
    'memory': new WebAssembly.Memory({initial: 100, limit: 1000}),
    'table': new WebAssembly.Table({initial: 0, element: 'anyfunc'})

Default deps are:

  'global': {},
  'env': {
    'memory': new Memory({initial: 10, limit: 100}),
    'table': new Table({initial: 0, element: 'anyfunc'})