- Install rust nightly toolchain and cargo
- Setup rust for wasm32-unknown-unknown target
- Install yarn (v3/4)
- Install plugin in the project with cargo workspaces yarn workspaces
yarn plugin import https://raw.githubusercontent.com/LIMPIX31/plugin-repack/master/yarn-plugin/bundles/@yarnpkg/plugin-repack.js
yarn repack install
cargo new --lib hello-world
[lib]
crate-type = ["cdylib"]
[repack]
target = "web" # or "nodejs"
[workspace]
members = [
"hello-world"
]
{
"name": "my-project",
"version": "1.0.0",
"main": "src/index.ts",
"dependencies": {
"@crate/hello-world": "crate:*"
}
}
yarn
# Try rebuild only hello-world
yarn repack rebuild hello-world
# Try rebuild all crates
yarn repack rebuild
# Try rebuild hello-world crate for release
yarn repack rebuild --release hello-world
import { hello_world } from '@crate/hello-world'
You can find examples in examples
branch
git checkout examples
export default defineConfig({
plugins: [react()],
build: {
target: 'esnext'
},
optimizeDeps: {
exclude: ['@crate/my-crate']
},
})
...is required. It is needed to restrict your dependencies semantically, so that you can understand that you are importing a crate and not something else