raw_module = "blah"
此属性与 JS 导入中的 module
属性 的作用完全相同,但它不会尝试将以 ./
、../
或 /
开头的路径解释为 JS 代码片段。 例如
#![allow(unused)] fn main() { #[wasm_bindgen(raw_module = "./some/js/file.js")] extern "C" { fn the_function(); } }
请注意,如果您将此属性与相对或绝对路径一起使用,则很可能最终的捆绑器或项目会为该路径赋予含义。这通常意味着 JS 文件或模块将相对于 Wasm 文件本身的最终位置进行解析。这意味着 raw_module
可能不适合 crates.io 上的库,但可能适用于最终用户应用程序。