3.0.2 • Published 3 months ago

rust-wasmpack-loader v3.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

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

parametertypedefaultdescription
webobjectoptions, which used for web target
nodeobjectoptions, which used for node target
web.asyncLoadingbooleanfalseenables load .wasm file asynchronously, instead of bundling in .js file
web.wasmPathModifierarray<string>["/"]rewrite wasm requestPath, if wrong publicPath used
web.publicPathbooleantrueuse webpack PublicPath
node.bundlebooleanfalseBundle .wasm file in .js file (additional .wasm file will not create)
logLevelstringinfoLog 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

3.0.2

3 months ago

3.0.0

5 months ago

2.3.2

11 months ago

2.3.4

10 months ago

2.3.3

10 months ago

2.3.6

10 months ago

2.3.5

10 months ago

2.3.0

1 year ago

2.2.1

1 year ago

2.3.1

1 year ago

2.2.0

1 year ago

2.1.1

1 year ago

2.1.0

2 years ago

1.1.1

2 years ago

1.0.2

2 years ago

2.0.0

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago