一覧へ戻る
Priemar/rollup-wasm-pack-import(新しいタブで開きます)
主要言語: JavaScript
Rollup plugin to use webassembly built with wasm-pack
- star 数
- 2
- watcher 数
- 1
- fork 数
- 1
- issue 数
- 0
- 最終更新
- 2021/01/12
主要言語: JavaScript
Rollup plugin to use webassembly built with wasm-pack
This plugin allows you to use WebAssembly built with wasm-pack in rollup. (+ This also works with (service)workers)
web)npm install --save-dev rollup-wasm-pack-import
rollup.config.js
import wasmImport from 'rollup-wasm-pack-import'; { plugins: [ wasmImport({ copy: true, serverPath: '/', mapping: { 'my-wasm-module': 'my-wasm.wasm' } }) ... ] }
Options object to configure wasm-pack-import.
| Property | Type | Description |
|---|---|---|
| copy | boolean | if true, the wasm will be copied in your output directory |
| mapping | object | key: module name of your wasm-pack npm modulevalue: the web assembly file name |
| outputDir | string | if copy is set to true, the wasm files will be copied in this directory |
| serverPath | string | path from the serve url where the wasm file is located. The path should always must always end with '/' |
Based on the current state of WebAssembly they need to be loaded async.
// if its installed via npm // if you are using a local directory built with wasm-pack, you can reference to '<relative-path>/pkg' (keep in mind to use the module name for options.mapping) import * as wasm from 'my-wasm-module'; async function load() { // initialize the web assembly await wasm.default(); console.log(wasm); // <your wasm code> }; load();
Version 2.0.0:
name from the "wasm-pack" built module (package.json) and the name of the wasm file aswell to check against the mapping key.serverPathI wrote this plugin for my personal specific prototypíng use case. This means if you have slightly differnt requirements this plugin should be more like an inspiration which you can use and adapt. (currently there are no error check / tests its more like a poc). I am looking forward for a pull request with a cleaned version. :)