0.0.1 • Published 7 years ago

rust-emscripten-loader v0.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Rust Webpack loader

npm

Usage

This is a simple Webpack loader that shells out to cargo to build a Rust project targeting either asm.js or WebAssembly. See this post for more details on using Rust to target the web.

To use it, first install the package:

$ npm install --save rust-emscripten-loader

then configure the loader in your Webpack config:

module.exports = {
  // ...
  module: {
    rules: [
      { test: /\.rs$/, loader: 'rust-emscripten-loader' },
      // ...
    ]
  }
}

Make sure you have the cargo, rustc, and emsdk binaries somewhere in your PATH.

When targeting WebAssembly, the loader will emit two additional files: one .wasm and one .js. You must specify the outName option to tell the loader how to name these files, and you'll need to load them info your HTML page in order to run the code. Check out the configuration and example sections below for more details.

Configuration

The following options can be added to the Webpack loader query:

NameDescriptionRequiredDefault
releaseWhether or not to pass the --release flag to cargofalsefalse
targetThe output target of the cargo build. Available options are asmjs and wasm.falseasmjs
outNameThe name of the output file for the wasm and js files when targeting wasmOnly when target is wasmnone

Example

Check out the example directory for a simple Hello World example targeting both asm.js and WebAssembly.