mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-28 14:27:36 +03:00
Expose on window.wasm_bindgen
This commit is contained in:
parent
ffdb8a6a32
commit
85c9f2319c
@ -231,17 +231,19 @@ impl<'a> Context<'a> {
|
||||
format!("var wasm;")
|
||||
} else if self.config.no_modules {
|
||||
format!("
|
||||
window.{module} = fetch('{module}_bg.wasm')
|
||||
window.wasm_bindgen.init = function(__wasm_path) {{
|
||||
return fetch(__wasm_path)
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(buffer => WebAssembly.instantiate(buffer, {{ './{module}': __exports }}))
|
||||
.then(({{instance}}) => {{
|
||||
wasm = instance.exports;
|
||||
return wasm;
|
||||
return;
|
||||
}})
|
||||
.catch(error => {{
|
||||
console.log('Error loading wasm module `{module}`:', error);
|
||||
throw error;
|
||||
}});
|
||||
}};
|
||||
", module = module_name)
|
||||
} else {
|
||||
format!("import * as wasm from './{}_bg';", module_name)
|
||||
@ -249,10 +251,13 @@ impl<'a> Context<'a> {
|
||||
|
||||
let js = if self.config.no_modules {
|
||||
format!("
|
||||
(function() {{
|
||||
let wasm;
|
||||
const __exports = {{}};
|
||||
{globals}
|
||||
window.wasm_bindgen = Object.assign({{}}, __exports);
|
||||
{import_wasm}
|
||||
}})();
|
||||
",
|
||||
globals = self.globals,
|
||||
import_wasm = import_wasm,
|
||||
|
Loading…
Reference in New Issue
Block a user