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 extraArgs
// defautls --typescript --target browser --mode normal
extraArgs: "--no-typescript --mode no-install",
}),
]
// ...
};
and then import your pkg
folder from wasm-pack
:
import("./path/to/your/pkg").then(module => {
module.run();
});