Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/limpix31/plugin-repack
One yarn plugin that can make wasm cozy
https://github.com/limpix31/plugin-repack
plugin rust wasm webassembly yarn yarn-pnp
Last synced: 10 days ago
JSON representation
One yarn plugin that can make wasm cozy
- Host: GitHub
- URL: https://github.com/limpix31/plugin-repack
- Owner: LIMPIX31
- License: bsd-3-clause
- Created: 2023-05-08T06:13:42.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-10-12T12:55:02.000Z (about 1 year ago)
- Last Synced: 2023-10-13T10:11:59.278Z (about 1 year ago)
- Topics: plugin, rust, wasm, webassembly, yarn, yarn-pnp
- Language: TypeScript
- Homepage:
- Size: 71.8 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Repack 1.1
###### Yarn plugin for easy integration of rust wasm into a web or nodejs project## Installation
1. [Install rust nightly toolchain and cargo](https://www.rust-lang.org/tools/install)
2. Setup rust for **wasm32-unknown-unknown** target
3. Install yarn (v3/4)
4. Install plugin in the project with cargo workspaces + yarn workspaces
```bash
yarn plugin import https://raw.githubusercontent.com/LIMPIX31/plugin-repack/master/yarn-plugin/bundles/@yarnpkg/plugin-repack.js
yarn repack install
```## Usage
### Create wasm crate
```bash
cargo new --lib hello-world
```#### ...and add target
```toml
[lib]
crate-type = ["cdylib"][repack]
target = "web" # or "nodejs"
```#### ...and add crate to cargo workspaces
```toml
[workspace]
members = [
"hello-world"
]
```### Add crate to yarn workspace dependencies and build
```json
{
"name": "my-project",
"version": "1.0.0",
"main": "src/index.ts",
"dependencies": {
"@crate/hello-world": "crate:*"
}
}
```#### ...then make the initial build
```bash
yarn
```### Rebuild crates
```
# 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 your crate
```ts
import { hello_world } from '@crate/hello-world'
```## Example
You can find examples in `examples` branch
```
git checkout examples
```## Known issues
### When using vite, you need to exclude crate
```ts
export default defineConfig({
plugins: [react()],
build: {
target: 'esnext'
},
optimizeDeps: {
exclude: ['@crate/my-crate']
},
})
```## Misc
### `@crate` scope
...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