wasm-module-webpack-plugin

Webpack loader that transforms wasm and glue js source files into javascript bundles.


Keywords
wasm, webpack, plugin, webassembly, babel
License
MIT
Install
npm install wasm-module-webpack-plugin@3.0.0

Documentation

WASM Module Webpack Plugin

npm Build Status Codacy Badge

NPM

中文文档

Load module which have wasm file into javascript with a zero bloat.

Installation

1 Run npm i wasm-module-webpack-plugin --save-dev. If you want use with webpack4, switch to old version 2.0.1

2 Require method from wasm-module-webpack-plugin

const WasmModuleWebpackPlugin = require('wasm-module-webpack-plugin');

3 Add this object to the rules section of your webpack build:

{
  test: /\.m?js$/,
  // exclude: /(node_modules|bower_components)/, // Do not set {exclude}
  include: [ '{your_code_dir}', path.join(process.cwd(), './node_modules/{wasm_module_name}') ],
  use: {
    loader: 'babel-loader',
    options: {
      presets: ['@babel/preset-env'],
      plugins: [
      '@babel/plugin-syntax-dynamic-import',
      // '@babel/plugin-transform-runtime', // Do not use plugin-transform-runtime
       WasmModuleWebpackPlugin.BabelPlugin
     ]
    }
  }
}

NOTE: Do not use it with @babel/plugin-transform-runtime

4 Add this object to the plugins section of your webpack build:

plugins: [
  new WasmModuleWebpackPlugin.WebpackPlugin()
]

Example

You can also view a complete working example on github here.

MIT License

Copyright 2018 zhi.zhou

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.