Skip to content

Latest commit

 

History

History
64 lines (51 loc) · 3.35 KB

README.zh-CN.md

File metadata and controls

64 lines (51 loc) · 3.35 KB

WASM Module Webpack Plugin

npm Build Status Codacy Badge

NPM

轻量级 加载含wasm文件的npm模块 的webpack插件

安装

1 运行 npm i wasm-module-webpack-plugin --save-dev, 如果希望配合webpack4使用该插件,请使用 2.0.1 版本

2 引入 wasm-module-webpack-plugin 模块

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

3 修改 rules 相关配置为如下所示

{
  test: /\.m?js$/,
  // exclude: /(node_modules|bower_components)/, // 不要设置exlude选项
  include: [ '{你的代码文件夹}', path.join(process.cwd(), './node_modules/{wasm模块名}') ],
  use: {
    loader: 'babel-loader',
    options: {
      presets: ['@babel/preset-env'],
      plugins: [
        '@babel/plugin-syntax-dynamic-import',
        // '@babel/plugin-transform-runtime', // 不要和这个插件一起使用
         WasmModuleWebpackPlugin.BabelPlugin
       ]
    }
  }
}

NOTE: 不要和 @babel/plugin-transform-runtime 这个插件一起使用

4 在 plugins 下添加以下配置

plugins: [
  new WasmModuleWebpackPlugin.WebpackPlugin()
]

示例

参考点击这里.

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.