You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

webassembly-loader

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webassembly-loader

Webpack loader for WebAssembly (like wasm-loader but have different export options)


Version published
Weekly downloads
482
decreased by-15.73%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

0.1.2 (2018-11-03)

Features

  • publish API docs on each release (#5) (e866dbb)

<a name="0.1.1"></a>

Readme

Source

npm size npm deps tests

webassembly-loader

this loader can also be used as a library ↙ see who use this?

tl;dr -- see examples

Motivation

future plans

Minimum Requirements

  • Node v8
  • Webpack v4

Installation

npm install webassembly-loader --save-dev

or

yarn add webassembly-loader --dev

Options

export

How wasm code would be exported. (see examples)

webpack.config.js
module.exports = {
    rules: [{
          test: /\.wasm$/,
          type: "javascript/auto",
          use: [{
              loader: "webassembly-loader",
              options: {
                  export: "async"
              }
          }]
    }]
}

tips: you can use query parameter to change export mode on demand

Examples

See the test cases and example projects in *.test.ts and examples for more insight.


{export: 'buffer'}
import wasmCode from "./lib.wasm";

WebAssembly.compile(wasmCode).then(module => {
  const instance = new WebAssembly.Instance(module);
  console(instance.exports.add(1, 2)); // 3
});

{export: 'module'}
import wasmModule from "./lib.wasm";

const instance = new WebAssembly.Instance(wasmModule);
console(instance.exports.add(1, 2)); // 3

{export: 'instance'}
import wasm from "./lib.wasm";

console(wasm.exports.add(1, 2)); // 3

{export: 'async'}
import wasmInstantiate from "./lib.wasm";

wasmInstantiate(importObject | undefined).then(({ instance, module }) => {
  console(instance.exports.add(1, 2)); // 3

  // create different instance, extra will be called in different environment
  const differentInstance = new WebAssembly.Instance(module);
  console(differentInstance.exports.add(1, 2)); // 6
});

{export: 'async-instance'}
import wasmInstantiate from "./lib.wasm";

wasmInstantiate(importObject | undefined).then(instance => {
  console(instance.exports.add(1, 2)); // 3
});

{export: 'async-module'}
import wasmInstantiate from "./lib.wasm";

wasmCompile(importObject | undefined).then(module => {
  const differentInstance = new WebAssembly.Instance(module);
  console(differentInstance.exports.add(1, 2)); // 3
});

Who use this?

Contributing

Credits


License

MIT

Keywords

FAQs

Package last updated on 17 Oct 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc