All Projects → ballercat → Wasm Loader

ballercat / Wasm Loader

Licence: mit
✨ WASM webpack loader

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Wasm Loader

Svgr
Transform SVGs into React components 🦁
Stars: ✭ 8,263 (+1268.05%)
Mutual labels:  webpack, webpack-loader, loader
Sass Vars Loader
Use Sass variables defined in Webpack config or in external Javascript or JSON files
Stars: ✭ 112 (-81.46%)
Mutual labels:  webpack, webpack-loader, loader
Thread Loader
Runs the following loaders in a worker pool
Stars: ✭ 945 (+56.46%)
Mutual labels:  webpack, webpack-loader, loader
Stylefmt Loader
Webpack-loader. Fixes stylelint issues automatically while bundling with Webpack.
Stars: ✭ 24 (-96.03%)
Mutual labels:  webpack, webpack-loader, loader
Carton
📦 Watcher, bundler, and test runner for your SwiftWasm apps
Stars: ✭ 171 (-71.69%)
Mutual labels:  webpack, webassembly, wasm
Style Loader
Style Loader
Stars: ✭ 1,572 (+160.26%)
Mutual labels:  webpack, webpack-loader, loader
Vue Svg Inline Loader
Webpack loader used for inline replacement of SVG images with actual content of SVG files in Vue projects.
Stars: ✭ 105 (-82.62%)
Mutual labels:  webpack, webpack-loader, loader
Sass Loader
Compiles Sass to CSS
Stars: ✭ 3,718 (+515.56%)
Mutual labels:  webpack, webpack-loader, loader
Pug As Jsx Loader
Stars: ✭ 168 (-72.19%)
Mutual labels:  webpack, webpack-loader, loader
Modern Wasm Starter
🛸 Run C++ code on web and create blazingly fast websites! A starter template to easily create WebAssembly packages using type-safe C++ bindings with automatic TypeScript declarations.
Stars: ✭ 140 (-76.82%)
Mutual labels:  webpack, webassembly, wasm
Markdown Loader
markdown loader for webpack
Stars: ✭ 335 (-44.54%)
Mutual labels:  webpack, webpack-loader, loader
Css Loader
CSS Loader
Stars: ✭ 4,067 (+573.34%)
Mutual labels:  webpack, webpack-loader, loader
Asmble
Compile WebAssembly to JVM and other WASM tools
Stars: ✭ 466 (-22.85%)
Mutual labels:  webassembly, wasm
Camaro
camaro is an utility to transform XML to JSON, using Node.js binding to native XML parser pugixml, one of the fastest XML parser around.
Stars: ✭ 438 (-27.48%)
Mutual labels:  webassembly, wasm
Astro
A fun safe language for rapid prototyping and high performance applications
Stars: ✭ 588 (-2.65%)
Mutual labels:  webassembly, wasm
Wasm And Rust
WebAssembly and Rust: A Web Love Story
Stars: ✭ 476 (-21.19%)
Mutual labels:  webassembly, wasm
Jwebassembly
Java bytecode to WebAssembly compiler
Stars: ✭ 426 (-29.47%)
Mutual labels:  webassembly, wasm
Inject Loader
💉📦 A Webpack loader for injecting code into modules via their dependencies.
Stars: ✭ 474 (-21.52%)
Mutual labels:  webpack-loader, loader
Genact
🌀 A nonsense activity generator
Stars: ✭ 5,109 (+745.86%)
Mutual labels:  webassembly, wasm
Awesome Wasm Runtimes
A list of webassemby runtimes
Stars: ✭ 490 (-18.87%)
Mutual labels:  webassembly, wasm

Build Status Package Quality

WASM Binary Module loader for Webpack

A simple .wasm binary file loader for Webpack. Import your wasm modules directly into your bundle as Constructors which return WebAssembly.Instance. This avoids the need to use fetch and parse for your wasm files. Imported wasm files are converted to Uint8Arrays and become part of the full JS bundle!

Install

Install package: npm install --save wasm-loader

Usage

Edit webpack.config.js:

  loaders: [
    {
      test: /\.wasm$/,
      loaders: ['wasm-loader']
    }
  ]

Optimizations

Dead code elemination

This is an experimental feature and thus not activated by default.

You can activate it by passing dce=1 to the import and by specifying manually (for now) the exported elements you use, like the following example:

import createInstance from "./add.wasm?dce=1&add&test"

createInstance()
.then(m => {
  console.log(m.instance.exports.add(1, 2));
  console.log(m.instance.exports.test());
});

Everything else in the add.wasm binary will be removed.

Include wasm from your code

Grab your pre-built wasm file. For demo purposes we will use the excellent WasmExplorer. factorial.wasm file exports a function returning a factorial for a given number.

With the loader you can import this file directy

import makeFactorial from 'wasm/factorial';

The default export from the loader is a function returning native Promise. The promise resolves to a WebAssembly.Instance.

makeFactorial().then(instance => {
  // What is with the weird exports._Z4facti function?
  // This is how the function name is encoded by the C++ to wasm compiler
  const factorial = instance.exports._Z4facti;

  console.log(factorial(1)); // 1
  console.log(factorial(2)); // 2
  console.log(factorial(3)); // 6
});

deps can be passed in to override defaults. For example

makeFactorial({
  'global': {},
  'env': {
    'memory': new WebAssembly.Memory({initial: 100, limit: 1000}),
    'table': new WebAssembly.Table({initial: 0, element: 'anyfunc'})
  }
}).then(instance => { /* code here */ });

Default deps are:

{
  'global': {},
  'env': {
    'memory': new Memory({initial: 10, limit: 100}),
    'table': new Table({initial: 0, element: 'anyfunc'})
  }
}

A note about default deps(importsObject)

Default importsObject is meant to be used for a very basic wasm module. Most likely it will not suffice for something not dead simple compiled with emscripten. This is intentional. Supply your own imports to match the requirements of your wasm module(s). Some options are compiling your source code into S-syntax(.wast) examining that output, checking the imports. Compile the s-syntax file with asm2wasm into the final wasm module.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].