Native wasm Webpack loader for .rs
(Rust) resources
Works with webpack
^5.0.0
Works fine with
web
andnode
(node-async
) targets
Dynamically finds the Cargo.toml
file for building the wasm source.
Provides the ability to use both wasm_bindgen
and regular functions.
Allows you to use the standard import of a .rs
file in a .js
or .ts
file without any headache
Install rust-wasmpack-loader
with npm
npm i rust-wasmpack-loader
Or install into Dev dependencies
npm i --save-dev rust-wasmpack-loader
Add .rs rule to webpack config
// webpack.config.js
module.exports = {
// ...
module: {
// ...
rules: [
// ...
{
test: /\.rs$/,
exclude: /node_modules/,
use: [
{
loader: "rust-wasmpack-loader",
},
],
},
]
}
}
Also, create Cargo.toml
file (in root or in folder, where you want to create .rs
file)
# Cargo.toml
[package]
name = "wasm-fibonacci-test"
version = "0.1.0"
authors = ["Yehor Brodskiy"]
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "0.2.73"
parameter | type | default | description |
---|---|---|---|
web |
object |
options, which used for web target |
|
node |
object |
options, which used for node target |
|
web.asyncLoading |
boolean |
false |
enables load .wasm file asynchronously, instead of bundling in .js file |
web.wasmPathModifier |
array<string> |
["/"] |
rewrite wasm requestPath, if wrong publicPath used |
web.publicPath |
boolean |
true |
use webpack PublicPath |
node.bundle |
boolean |
false |
Bundle .wasm file in .js file (additional .wasm file will not create) |
logLevel |
string |
info |
Log Level (verbose , info , warn , error , quiet ) |
Check the example folder for a better understanding of how the loader works
Contributions are always welcome!
See CONTRIBUTING.md for ways to get started.