#leptos #js #generate #macro #file #bindings #file-path

macro wasmbind-js-file-macro

Provide a macro to generate JavaScript bindings from an external JS file

2 releases

new 0.1.6 Nov 24, 2024
0.1.5 Nov 8, 2024
0.1.2 Oct 28, 2024

#144 in #leptos

Download history 287/week @ 2024-10-20 163/week @ 2024-10-27 369/week @ 2024-11-03 42/week @ 2024-11-10 6/week @ 2024-11-17

600 downloads per month
Used in trading-charts

MIT license

6KB
64 lines

Crates.io Docs.rs

Wasmbind JS File Macro

Provide a macro to generate JavaScript bindings from an external JS file.

The procedural macro will generate the #[wasm_bindgen] attribute with parameter inline_js. The parameter inline_js will be filled by this macro with the content of the file that the path is passed as the argument path of this macro. The path can contain ${outDir} placeholders which is the value of the OUT_DIR environment variable.

Pre-requisites

The crate wasm-bindgen must be in the dependencies of the project.

Example

use wasmbind_js_macro::wasmbind_js;

#[wasmbind_dump_js_file_as_inline(path = "${outDir}/js/external.js")]
extern "C" {
    fn external_function();
}

This will generate the following code:

#[wasm_bindgen(inline_js = r###" ... here is the content of the file external.js ... "###)]
extern "C" {
    fn external_function();
}

Dependencies

~210–640KB
~15K SLoC