All Projects → ianjsikes → rust-wasm-loader

ianjsikes / rust-wasm-loader

Licence: MIT license
Webpack loader for Rust

Programming Languages

javascript
184084 projects - #8 most used programming language
rust
11053 projects
HTML
75241 projects

Projects that are alternatives of or similar to rust-wasm-loader

emscripten-webxr
WebXR library for use with Emscripten.
Stars: ✭ 21 (-74.07%)
Mutual labels:  wasm
fastlike
Run Fastly Compute@Edge Wasm programs on your own computer, powered by wasmtime
Stars: ✭ 36 (-55.56%)
Mutual labels:  wasm
epick
Color picker for creating harmonic color palettes that works on Linux, Windows, macOS and web.
Stars: ✭ 89 (+9.88%)
Mutual labels:  wasm
go-wasm-pdfcpu
Running a Command line tool written in Go on browser with WebAssembly
Stars: ✭ 79 (-2.47%)
Mutual labels:  wasm
rotation master
Provide conversion between the major representations of 3D rotation and visualize the orientation of a rigid body
Stars: ✭ 157 (+93.83%)
Mutual labels:  wasm
tiny-secp256k1
A tiny secp256k1 native/JS wrapper
Stars: ✭ 41 (-49.38%)
Mutual labels:  wasm
vgg runtime
VGG Runtime for loading and running designs as apps.
Stars: ✭ 19 (-76.54%)
Mutual labels:  wasm
AheuiJIT
Aheui JIT compiler for PC and web
Stars: ✭ 27 (-66.67%)
Mutual labels:  wasm
bounce
The uncomplicated Yew State management library
Stars: ✭ 43 (-46.91%)
Mutual labels:  wasm
rabin-wasm
Rabin fingerprinting implemented in WASM
Stars: ✭ 26 (-67.9%)
Mutual labels:  wasm
wsPlayer
wsPlayer is a web video player based on WebSocket-fmp4.
Stars: ✭ 88 (+8.64%)
Mutual labels:  wasm
wasp
🐝 Wasp : Wasm programming (language)
Stars: ✭ 93 (+14.81%)
Mutual labels:  wasm
wasm-adventure
My adventure into the marvelous world of Web Assembly
Stars: ✭ 49 (-39.51%)
Mutual labels:  wasm
watpl
Create WebAssembly modules using template strings
Stars: ✭ 14 (-82.72%)
Mutual labels:  wasm
jupiter
Wasm smart contract networks powered by Substrate FRAME Contracts pallet in Polkadot ecosystem.
Stars: ✭ 49 (-39.51%)
Mutual labels:  wasm
aWsm
WebAssembly ahead-of-time compiler and runtime. Focuses on generating fast code, simplicity, and portability.
Stars: ✭ 177 (+118.52%)
Mutual labels:  wasm
boids
🦢 The boids flocking simulation in Wasm using Ebiten!
Stars: ✭ 56 (-30.86%)
Mutual labels:  wasm
WebAssembly-in-Action
Source code for the book "WebAssembly in Action" (https://www.manning.com/books/webassembly-in-action)
Stars: ✭ 44 (-45.68%)
Mutual labels:  wasm
pigmnts
🎨 Color palette generator from an image using WebAssesmbly and Rust
Stars: ✭ 38 (-53.09%)
Mutual labels:  wasm
matchbox
Painless peer-to-peer WebRTC networking for rust wasm
Stars: ✭ 276 (+240.74%)
Mutual labels:  wasm

Rust WebAssembly loader

npm

Usage

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

To use it, first install the package:

$ npm install rust-wasm-loader

Configure the loader in your Webpack config:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.rs$/,
        use: {
          loader: 'rust-wasm-loader',
          options: {
            // Path to your 'build' or 'dist' directory relative to project root
            path: 'build/',
          }
        }
      },
      // ...
    ]
  }
}

Note: if you are using file-loader, make sure to add .wasm to the test field, otherwise the module will not be copied! (e.g. test: /\.(wasm|jpg|jpeg|png|gif|svg|eot|ttf|woff|woff2)$/i,).

Make sure you have the cargo, rustc, and (optionally) emsdk binaries somewhere in your PATH. stdweb and other Rust libraries require a nightly build, which can be installed from https://rustup.rs/ .

Require and initialize the wasm module:

const wasm = require('./lib.rs')
wasm.then(module => {
  // Use your module here
  console.log(module.doub(21))
})

or with async/await:

async function loadwasm() {
  const lib = await require('./lib.rs');
  // Use your module here
  console.log(lib.doub(21));
}
loadwasm();

Configuration

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

Name Description Required Default
release Whether or not to pass the --release flag to cargo false false
path Path to your webpack output folder relative to project root true ''
target Allows one to specify wasm32-unknown-emscripten as build target false 'wasm32-unknown-unknown'

Example

Check out the example directory for a simple Hello World example.

This project is based off of rust-emscripten-loader by mrdziuban.

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].