mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-01 06:46:20 +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;")
|
format!("var wasm;")
|
||||||
} else if self.config.no_modules {
|
} else if self.config.no_modules {
|
||||||
format!("
|
format!("
|
||||||
window.{module} = fetch('{module}_bg.wasm')
|
window.wasm_bindgen.init = function(__wasm_path) {{
|
||||||
|
return fetch(__wasm_path)
|
||||||
.then(response => response.arrayBuffer())
|
.then(response => response.arrayBuffer())
|
||||||
.then(buffer => WebAssembly.instantiate(buffer, {{ './{module}': __exports }}))
|
.then(buffer => WebAssembly.instantiate(buffer, {{ './{module}': __exports }}))
|
||||||
.then(({{instance}}) => {{
|
.then(({{instance}}) => {{
|
||||||
wasm = instance.exports;
|
wasm = instance.exports;
|
||||||
return wasm;
|
return;
|
||||||
}})
|
}})
|
||||||
.catch(error => {{
|
.catch(error => {{
|
||||||
console.log('Error loading wasm module `{module}`:', error);
|
console.log('Error loading wasm module `{module}`:', error);
|
||||||
throw error;
|
throw error;
|
||||||
}});
|
}});
|
||||||
|
}};
|
||||||
", module = module_name)
|
", module = module_name)
|
||||||
} else {
|
} else {
|
||||||
format!("import * as wasm from './{}_bg';", module_name)
|
format!("import * as wasm from './{}_bg';", module_name)
|
||||||
@ -249,10 +251,13 @@ impl<'a> Context<'a> {
|
|||||||
|
|
||||||
let js = if self.config.no_modules {
|
let js = if self.config.no_modules {
|
||||||
format!("
|
format!("
|
||||||
|
(function() {{
|
||||||
let wasm;
|
let wasm;
|
||||||
const __exports = {{}};
|
const __exports = {{}};
|
||||||
{globals}
|
{globals}
|
||||||
|
window.wasm_bindgen = Object.assign({{}}, __exports);
|
||||||
{import_wasm}
|
{import_wasm}
|
||||||
|
}})();
|
||||||
",
|
",
|
||||||
globals = self.globals,
|
globals = self.globals,
|
||||||
import_wasm = import_wasm,
|
import_wasm = import_wasm,
|
||||||
|
Loading…
Reference in New Issue
Block a user