Simplified the preamble

This commit is contained in:
Sharad Chand 2018-04-12 10:31:13 +05:45
parent aa6487b6f1
commit ffdb8a6a32

View File

@ -231,9 +231,9 @@ impl<'a> Context<'a> {
format!("var wasm;")
} else if self.config.no_modules {
format!("
return fetch('{module}_bg.wasm')
window.{module} = fetch('{module}_bg.wasm')
.then(response => response.arrayBuffer())
.then(buffer => WebAssembly.instantiate(buffer, __js_exports))
.then(buffer => WebAssembly.instantiate(buffer, {{ './{module}': __exports }}))
.then(({{instance}}) => {{
wasm = instance.exports;
return wasm;
@ -249,22 +249,11 @@ impl<'a> Context<'a> {
let js = if self.config.no_modules {
format!("
(function (root, factory) {{
if (typeof define === 'function' && define.amd) {{
define([], factory);
}} else {{
root.{module} = factory();
}}
}}(typeof self !== 'undefined' ? self : this, function() {{
let wasm;
const __js_exports = {{}};
const __exports = {{}};
{globals}
__js_exports['./{module}'] = __exports;
{import_wasm}
}}))
let wasm;
const __exports = {{}};
{globals}
{import_wasm}
",
module = module_name,
globals = self.globals,
import_wasm = import_wasm,
)