mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-20 00:11:23 +00:00
Add a raw_module
attribute to #[wasm_bindgen]
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
This commit is contained in:
@ -66,6 +66,7 @@
|
||||
- [`js_namespace`](./reference/attributes/on-js-imports/js_namespace.md)
|
||||
- [`method`](./reference/attributes/on-js-imports/method.md)
|
||||
- [`module = "blah"`](./reference/attributes/on-js-imports/module.md)
|
||||
- [`raw_module = "blah"`](./reference/attributes/on-js-imports/raw_module.md)
|
||||
- [`static_method_of = Blah`](./reference/attributes/on-js-imports/static_method_of.md)
|
||||
- [`structural`](./reference/attributes/on-js-imports/structural.md)
|
||||
- [`variadic`](./reference/attributes/on-js-imports/variadic.md)
|
||||
|
@ -31,3 +31,8 @@ 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)
|
||||
|
19
guide/src/reference/attributes/on-js-imports/raw_module.md
Normal file
19
guide/src/reference/attributes/on-js-imports/raw_module.md
Normal file
@ -0,0 +1,19 @@
|
||||
# `raw_module = "blah"`
|
||||
|
||||
This attribute performs exactly the same purpose as the [`module`
|
||||
attribute](module.html) on JS imports, but it does not attempt to interpret
|
||||
paths starting with `./`, `../`, or `/` as JS snippets. For example:
|
||||
|
||||
```rust
|
||||
#[wasm_bindgen(raw_module = "./some/js/file.js")]
|
||||
extern "C" {
|
||||
fn the_function();
|
||||
}
|
||||
```
|
||||
|
||||
Note that if you use this attribute with a relative or absolute path, it's
|
||||
likely up to the final bundler or project to assign meaning to that path. This
|
||||
typically means that the JS file or module will be resolved relative to the
|
||||
final location of the wasm file itself. That means that `raw_module` is likely
|
||||
unsuitable for libraries on crates.io, but may be usable within end-user
|
||||
applications.
|
Reference in New Issue
Block a user