npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

binaryen-loader

v0.1.1

Published

A webpack loader to reduce WebAssembly file binary size, based on Binaryen

Downloads

14

Readme

npm node deps tests size

binaryen-loader

A loader to reduce wasm code size based on Binaryen.

Requirements

This module requires a minimum of Node v6.9.0 and Webpack v4.0.0.

Getting Started

To begin, you'll need to install binaryen-loader:

$ npm install binaryen-loader --save-dev

Then add the loader to your webpack config. For example:

file.wasm

import file from 'file.wasm';

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.wasm$/,
        use: [
          {
            loader: `binaryen-loader`,
            options: {...options}
          }
        ]
      }
    ]
  }
}

And run webpack via your preferred method.

Options

The options in binaryen-loader correspond to module-optimization section in binaryen.js.

debug

  • Type: Boolean
  • Default: false
  • Correspond to: setDebugInfo

Enables or disables debug information in emitted binaries.

// in your webpack.config.js
{
  loader: `binaryen-loader`,
  options: {
    debug: true
  }
}

optimization.level

  • Type: Integer
  • Default: 2
  • Expected value: from 0 to 2
  • Correspond to: setOptimizeLevel

Sets the optimization level that correspond to flag -O0, -O1, -O2, etc.

// in your webpack.config.js
{
  loader: `binaryen-loader`,
  options: {
    optimization: {
      level: 0
    }
  }
}

optimization.shrinkLevel

  • Type: Integer
  • Default: 1
  • Expected value: from 0 to 2
  • Correspond to: setShrinkLevel

Sets the shrink level that correspond to flag -O0, -Os, -Oz.

// in your webpack.config.js
{
  loader: `binaryen-loader`,
  options: {
    optimization: {
      shrinkLevel: 2
    }
  }
}

transformation.passes

Runs the specified passes on the module.

// in your webpack.config.js
{
  loader: `binaryen-loader`,
  options: {
    transformation: {
      passes: 'post-emscripten'
    }
  }
}

or

// in your webpack.config.js
{
  loader: `binaryen-loader`,
  options: {
    transformation: {
      passes: [
        'post-emscripten',
        'remove-memory'
      ]
    }
  }
}

transformation.function (still experimental)

  • Type: String
  • Default: null
  • Expected value: any valid function name exported from .wasm file
  • Correspond to: optimizeFunction (if passes undefined) or runPassesOnFunction (if passes defined)

Optimizes a single function using defined and/or default passes.

// in your webpack.config.js
{
  loader: `binaryen-loader`,
  options: {
    transformation: {
      function: 'add'
    }
  }
}

Examples

The following examples show how to use binaryen-loader chained with wasm-loader.

chain illustration

webpack.config.js

module.exports = {
  module: {
    rules: [{
      test: /\.wasm$/,
      use: [{
        loader: 'wasm-loader'
      }, {
        loader: `binaryen-loader`,
        options: {
          transformation: {
            passes: [
              'post-emscripten',
              'remove-memory'
            ]
          }
        }
      }]
    }]
  }
}

arithmatic.wasm (if converted into .wat)

(module
  (type $t0 (func (param i32 i32) (result i32)))
  (func $add (export "add") (type $t0) (param $0 i32) (param $1 i32) (result i32)
    get_local $0
    get_local $1
    i32.add)
  (memory $memory (export "memory") 1))

implementation.js

import loadArithmatic from 'arithmatic.wasm';

loadArithmatic.then(wasm =>
  const { add } = wasm.instance.exports;
  console.log(add(1, 2)); // 3
);

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT


This project generated and modified based on webpack-defaults. Default Contribution guideline, Issue and PR template are intentionally left behind, not edited until there is some feedback about that 🙂