Basic boilerplate configuration to import a local rust library in a vite based environment
You need to install npm and rust Installing npm Installing rust
To build the package, we need an additional tool, wasm-pack. This helps compile the code to WebAssembly, as well as produce the right packaging for use in the browser.
cargo install wasm-pack
For more information visit mdn Compiling from Rust to WebAssembly
After running npm install is also necessary to build the rust library due to interoperability between the vite project and the lib, imported as dependency and initialized before creating the react root node.
cd app
npm run install
npm run build:wasm
You can run the project by simply using
npm run dev
Building will recompile the rust library, and then the vite project.
npm run build