Available loader options

release: boolean; whether to compile the WebAssembly module in debug or release mode;
defaults to false.

gc: boolean; whether to run wasm-gc on the WebAssembly output. Reduces binary size but
requires installing wasm-gc. Defaults to false and is a no-op in wasmBindgen or
cargoWeb mode.

target: string; the Rust target to use; this defaults to wasm32-unknown-unknown

wasmBindgen: boolean or object; use wasm-bindgen to post-process the wasm file. This
probably means that you need to chain this loader with babel-loader as well since
wasm-bindgen outputs ES6 (or typescript).

wasmBindgen.debug: boolean; run wasm-bindgen in debug mode.

wasmBindgen.wasm2es6js: boolean; use wasm2es6js to inline the wasm file into generated
Javascript. Useful if webpack is not configured to load wasm files via some other loader.

wasmBindgen.typescript: boolean; emit a typescript declaration file as part of the
build. This file will automatically be referenced, and in a way that ts-loader will pick
it up but it's still possible to treat the output from this loader like a normal Javascript
module compatible with babel-loader.

cargoWeb: boolean or object; use cargo-web to compile the project instead of only
building a wasm module. Defaults to false.

cargoWeb.name: string; the file name to use for emitting the wasm file for cargo-web,
e.g. 'static/wasm/[name].[hash:8].wasm'.

cargoWeb.regExp: string; a regexp to extract additional variables for use in name.

Long version

First, you need Rust installed. The easiest way is to follow the instructions at rustup.rs.

Then, you need to add support for WebAssembly cross-compilation. At the time of writing, this
requires using the nightly compiler:

The loader now uses wasm-bindgen to build the project. If you are using webpack 4, it has experimental native support for importing WASM files, so you probably
don't need the wasm2es6js flag. If you are using webpack 3 (or bundling for Chrome and it's 4K limit on main thread WASM), it is needed in order to inline
the loading of the wasm file correctly. By using wasm2es6js, the loader returns a normal Javascript module that can
be loaded like so: