Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrdziuban/rust-emscripten-loader
Webpack loader for Rust + Emscripten
https://github.com/mrdziuban/rust-emscripten-loader
Last synced: about 2 months ago
JSON representation
Webpack loader for Rust + Emscripten
- Host: GitHub
- URL: https://github.com/mrdziuban/rust-emscripten-loader
- Owner: mrdziuban
- License: mit
- Created: 2017-03-05T01:58:41.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-14T17:59:03.000Z (almost 7 years ago)
- Last Synced: 2024-03-23T13:22:40.021Z (10 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 34
- Watchers: 3
- Forks: 23
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rust Webpack loader
[![npm](https://img.shields.io/npm/v/rust-emscripten-loader.svg)](https://www.npmjs.com/package/rust-emscripten-loader)
### Usage
This is a simple Webpack loader that shells out to cargo to build a Rust project targeting either asm.js or
WebAssembly. See [this post](https://users.rust-lang.org/t/compiling-to-the-web-with-rust-and-emscripten/7627) for
more details on using Rust to target the web.To use it, first install the package:
```bash
$ npm install --save rust-emscripten-loader
```then configure the loader in your Webpack config:
```js
module.exports = {
// ...
module: {
rules: [
{ test: /\.rs$/, loader: 'rust-emscripten-loader' },
// ...
]
}
}
```Make sure you have the `cargo`, `rustc`, and `emsdk` binaries somewhere in your `PATH`.
When targeting WebAssembly, the loader will emit two additional files: one `.wasm` and one `.js`. You must specify
the `outName` option to tell the loader how to name these files, and you'll need to load them info your HTML page in
order to run the code. Check out the configuration and example sections below for more details.### Configuration
The following options can be added to the Webpack loader query:
| Name | Description | Required | Default |
| ---- | ----------- | -------- | ------- |
| `release` | Whether or not to pass the `--release` flag to cargo | false | false |
| `target` | The output target of the cargo build. Available options are `asmjs` and `wasm`. | false | `asmjs` |
| `outName` | The name of the output file for the `wasm` and `js` files when targeting `wasm` | Only when target is `wasm` | none |### Example
Check out the [example](example) directory for a simple Hello World example targeting both asm.js and WebAssembly.