added default module path inside init function when target is web

This commit is contained in:
ibaryshnikov
2019-06-08 01:27:35 +03:00
parent 96d333af84
commit 8ace8287ff
2 changed files with 18 additions and 2 deletions

View File

@ -450,6 +450,17 @@ impl<'a> Context<'a> {
} else {
""
};
let default_module_path = match self.config.mode {
OutputMode::Web => {
"\
if (typeof module === 'undefined') {
module = import.meta.url.replace(/\\.js$/, '_bg.wasm');
}"
}
_ => "",
};
let ts = Self::ts_for_init_fn(mem.import.is_some());
// Initialize the `imports` object for all import definitions that we're
@ -475,6 +486,7 @@ impl<'a> Context<'a> {
let js = format!(
"\
function init(module{init_memory_arg}) {{
{default_module_path}
let result;
const imports = {{}};
{imports_init}
@ -518,6 +530,7 @@ impl<'a> Context<'a> {
}}
",
init_memory_arg = init_memory_arg,
default_module_path = default_module_path,
init_memory1 = init_memory1,
init_memory2 = init_memory2,
start = if needs_manual_start {