GithubHelp home page GithubHelp logo

isabella232 / rollup-plugin-wasm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rollup/rollup-plugin-wasm

0.0 0.0 0.0 34 KB

This module has moved and is now available at @rollup/plugin-wasm / https://github.com/rollup/plugins

JavaScript 25.48% WebAssembly 74.52%

rollup-plugin-wasm's Introduction

Moved

This module has moved and is now available at @rollup/plugin-wasm. Please update your dependencies. This repository is no longer maintained.

rollup-plugin-wasm

semantic-release

Rollup plugin for importing WebAssembly modules.

Use this Rollup plugin to import WebAssembly modules and bundle them as base64 strings. They are imported async (but small modules can be imported sync).

Install

npm i -D rollup-plugin-wasm

Configuration

Add the plugin to your rollup config and then any imported .wasm file will be processed by it.

import wasm from 'rollup-plugin-wasm'

export default {
  input: 'web/index.js',
  plugins: [
    wasm()
  ]
}

Example

Given the following simple C file (compiled using emscripten, or the online WasmFiddle tool):

int main() {
  return 42;
}

Import and instantiate the resulting file:

import wasm from './sample.wasm';

wasm({ ...imports }).then(({ instance }) => {
  console.log(instance.exports.main())
})

The WebAssembly is inlined as a base64 encoded string (which means it will be ~33% larger than the original). At runtime the string is decoded and a module is returned.

Sync Modules

Small modules (< 4KB) can be compiled synchronously by specifying them in the configuration.

wasm({
  sync: [
    'web/sample.wasm',
    'web/foobar.wasm'
  ]
})

This means that the exports can be accessed immediately.

import module from './sample.wasm'

const instance = sample({ ...imports })

console.log(instance.exports.main())

rollup-plugin-wasm's People

Contributors

ballercat avatar colineberhardt avatar grinat avatar hasangenc0 avatar jamen avatar rajeevriitm avatar shellscape avatar xmclark avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.