mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-05-11 05:17:16 +00:00
This allows subverting the checks and resolution performed by the `module` attribute added as part of [RFC 6] and has been discussed in #1343. Closes #1343 [RFC 6]: https://github.com/rustwasm/rfcs/pull/6
39 lines
827 B
Markdown
39 lines
827 B
Markdown
# `module = "blah"`
|
|
|
|
The `module` attributes configures the module from which items are imported. For
|
|
example,
|
|
|
|
```rust
|
|
#[wasm_bindgen(module = "wu/tang/clan")]
|
|
extern "C" {
|
|
type ThirtySixChambers;
|
|
}
|
|
```
|
|
|
|
generates JavaScript import glue like:
|
|
|
|
```js
|
|
import { ThirtySixChambers } from "wu/tang/clan";
|
|
```
|
|
|
|
If a `module` attribute is not present, then the global scope is used
|
|
instead. For example,
|
|
|
|
```rust
|
|
#[wasm_bindgen]
|
|
extern "C" {
|
|
fn illmatic() -> u32;
|
|
}
|
|
```
|
|
|
|
generates JavaScript import glue like:
|
|
|
|
```js
|
|
let illmatic = this.illmatic;
|
|
```
|
|
|
|
Note that if the string specified with `module` starts with `./`, `../`, or `/`
|
|
then it's interpreted as a path to a [local JS snippet](../../js-snippets.html).
|
|
If this doesn't work for your use case you might be interested in the
|
|
[`raw_module` attribute](raw_module.html)
|