https://github.com/xxshady/altv-esbuild-rust-wasm
esbuild plugin for using Rust via JS WASM on alt:V
https://github.com/xxshady/altv-esbuild-rust-wasm
altv esbuild esbuild-plugin fivem gta5 gtav ragemp rust-lang wasm
Last synced: about 2 months ago
JSON representation
esbuild plugin for using Rust via JS WASM on alt:V
- Host: GitHub
- URL: https://github.com/xxshady/altv-esbuild-rust-wasm
- Owner: xxshady
- Created: 2022-08-14T22:57:00.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-18T00:49:51.000Z (about 1 year ago)
- Last Synced: 2024-09-18T04:40:25.410Z (about 1 year ago)
- Topics: altv, esbuild, esbuild-plugin, fivem, gta5, gtav, ragemp, rust-lang, wasm
- Language: JavaScript
- Homepage:
- Size: 2.3 MB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# altv-esbuild-rust-wasm
esbuild plugin that helps you to use rust with wasm in alt:V on serverside and clientside.
Requirement for building rust to wasm is installed [wasm-pack](https://rustwasm.github.io/docs/wasm-pack).
## How to use?
Ready-to-use [examples](./examples).
### Install package via npm
```cmd
npm i altv-esbuild-rust-wasm
```### Add to plugins
```js
import esbuild from "esbuild"esbuild.build({
// ...
plugins: [
altvEsbuildRustWasm({
// or "server", depending on where you need to load WASM binary
target: "client"// absolute path of .wasm file for `alt.File.read`
// only needed for clientside
wasmPathForClientRead: "/client/rust_wasm_bg.wasm"
}),
],
})
```### Usage in JS code
```js
import loadWasm from "./pkg/example.wasm"const {
// these values are exported from rust
// (see examples)
...wasmExports
} = loadWasm({
// these values are imported to rust using:
// #[wasm_bindgen(js_namespace = altv_imports)]
...wasmImports,
})
```See `wasm-bingen` documentation: [exports](https://rustwasm.github.io/docs/wasm-bindgen/reference/attributes/on-rust-exports/index.html) and [imports](https://rustwasm.github.io/docs/wasm-bindgen/reference/attributes/on-js-imports/index.html).