rust-wasmpack-loader

3.0.2 • Public • Published

MIT License View this project on NPM View this project on NPM Quality Gate Status Known Vulnerabilities

Rust Wasm-pack Loader

Native wasm Webpack loader for .rs (Rust) resources

Works with webpack ^5.0.0

Works fine with web and node (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

Installation

Please be sure, that cargo and rustup are installed

Install rust-wasmpack-loader with npm

  npm i rust-wasmpack-loader

Or install into Dev dependencies

  npm i --save-dev rust-wasmpack-loader

Usage

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"

Options

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)

Examples

Check the example folder for a better understanding of how the loader works

Contributing

Contributions are always welcome!

See CONTRIBUTING.md for ways to get started.

Acknowledgements

License

MIT

Package Sidebar

Install

npm i rust-wasmpack-loader

Weekly Downloads

35

Version

3.0.2

License

MIT

Unpacked Size

26 kB

Total Files

8

Last publish

Collaborators

  • yeskiy