Webpack plugin for Rust
yarn add --dev @wasm-tool/wasm-pack-plugin
We expect wasm-pack
to be in your $PATH
. See installation here.
Add the loader in your webpack.config.js
:
module.exports = {
// ...
plugins: [
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, "crate"),
// Check https://rustwasm.github.io/wasm-pack/book/commands/build.html for
// the available set of arguments.
//
// Default arguments are `--typescript --target browser --mode normal`.
extraArgs: "--no-typescript",
}),
]
// ...
};
and then import your pkg
folder from wasm-pack
:
import("./path/to/your/pkg").then(module => {
module.run();
});