embed_js

Crates.ioembed_js
lib.rsembed_js
version0.1.4
sourcesrc
created_at2017-12-17 11:48:27.71967
updated_at2017-12-21 21:44:23.198778
descriptionMinimalist lightweight inline JavaScript for Rust applications targeting WebAssembly via the `wasm32-unknown-unknown` target. See also embed_js_build, the accompanying crate for use by build scripts.
homepagehttps://github.com/dylanede/embed_js
repositoryhttps://github.com/dylanede/embed_js
max_upload_size
id43398
size6,343
Dylan Ede (dylanede)

documentation

https://docs.rs/embed_js

README

embed_js

Minimalist lightweight inline JavaScript for Rust applications targeting WebAssembly via the wasm32-unknown-unknown target.

This project provides a low level interface designed for other crates to build higher level, more ergonomic APIs on top of.

Getting started

Try out the examples (in the examples subdirectory) to get a feel of how the pieces fit together.

To build wasm applications, make sure you have both a recent Rust nightly and the wasm32-unknown-unknown target installed.

Setting up the examples

The examples require cargo-make, cargo-script and wasm-gc to be installed.

In an example's directory, make sure you have rustup set up to build with nightly Rust.

Build the example using cargo make, which ensures that the post-build script is run. The resulting self-contained HTML file should be in "target/wasm32-unknown-unknown/release/" and can be ran in a browser (one that supports WebAssembly).

Depending on the example you may need to check the console log in the browser (F12) to see its output.

General usage

There are two crates to use. embed_js is for crates using the js macro to embed JavaScript. embed_js_build should be used by those crates as a pre-processing stage in their build scripts. embed_js_build should also be used by application crates that build wasm binaries in their post-build scripts in order to gather the generated accompanying JavaScript to import when loading the wasm module.

See the documentation of both crates for more detailed usage information, or check out the examples in this repository.

embed_js Documentation

embed_js_build Documentation

[dependencies]
embed_js = "^0.1.4"
[build-dependencies]
embed_js_build = "^0.1.4"

Limitations

Currently the js macro cannot be used inside other macros, with the exception of the include! macro. This is potentially fixable in the future.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 23

cargo fmt