rust-loader
Webpack Rust loader
Webpack loader for Rust
Example
add.rs
pub fn add(a: i32, b: i32) -> i32 { a + b}huge_crate/Cargo.toml
[lib]crate-type = ["cdylib"] # importanthuge_crate/src/lib.rs
fn its_magic_number(x: i32) -> bool { x == 42}pub fn plus_one(x: i32) -> i32 { if its_magic_number(x) { 420 } else { x + 1 }}main.js
async { const add = await add const hugeCrate = await hugeCrate console // 3 console // 7 console // 420}Features
- Dont injects WASM to JS bundle, dynamic http fetching
.wasmfiles viafile-loader - Hot module replacement
Usage
- Prepare system
- Install nightly Rust:
rustup update nightly - Install rustc wasm target:
rustup target add wasm32-unknown-unknown --toolchain nightly - Install wasm-gc:
cargo install --git https://github.com/alexcrichton/wasm-gc --force
- Install nightly Rust:
- Configure Webpack
- Install
rust-loaderandfile-loader:yarn add rust-loader file-loader --dev - Use it in Webpack config:
rules:test: //loader: "rust-loader"test: /\.wasm$/loader: "file-loader" - Install