diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index 9472ec752e9f8..15f6ffdc4ba9f 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -182,6 +182,15 @@ var imports = { }; #if MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION +{{{ +#if EXPORT_ES6 && !ENVIRONMENT_MAY_BE_AUDIO_WORKLET +const moduleUrl = `new URL('${TARGET_BASENAME}.wasm', import.meta.url)`; +#elif !EXPORT_ES6 || AUDIO_WORKLET +const moduleUrl = `'${TARGET_BASENAME}.wasm'`; +#else +const moduleUrl = `ENVIRONMENT_IS_AUDIO_WORKLET ? '${TARGET_BASENAME}.wasm' : new URL('${TARGET_BASENAME}.wasm', import.meta.url)`; +#endif +}}} // https://caniuse.com/#feat=wasm and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming #if MIN_SAFARI_VERSION < 150000 || ENVIRONMENT_MAY_BE_NODE #if ASSERTIONS && !WASM2JS @@ -197,13 +206,13 @@ instantiatePromise = // Node's fetch API cannot be used for local files, so we cannot use instantiateStreaming && !ENVIRONMENT_IS_NODE #endif - ? WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports) + ? WebAssembly.instantiateStreaming(fetch({{{ moduleUrl }}}), imports) : WebAssembly.instantiate(Module['wasm'], imports)).then((output) => { #else #if AUDIO_WORKLET instantiatePromise = #endif -WebAssembly.instantiateStreaming(fetch('{{{ TARGET_BASENAME }}}.wasm'), imports).then((output) => { +WebAssembly.instantiateStreaming(fetch({{{ moduleUrl }}}), imports).then((output) => { #endif #else // Non-streaming instantiation diff --git a/test/test_browser.py b/test/test_browser.py index 3b8b21600a591..b77053e3ed537 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -5557,9 +5557,13 @@ def test_webpack(self, args): @also_with_threads @requires_dev_dependency('vite') - def test_vite(self): + @parameterized({ + '': ([],), + 'minimal': (['-sMINIMAL_RUNTIME', '-sMINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION'],), + }) + def test_vite(self, args): copytree(test_file('vite'), '.') - self.compile_btest('hello_world.c', ['-sEXIT_RUNTIME', '-sENVIRONMENT=web', '-o', 'hello.mjs']) + self.compile_btest('hello_world.c', ['-sEXIT_RUNTIME', '-sENVIRONMENT=web', '-o', 'hello.mjs'] + args) self.run_process(shared.get_npm_cmd('vite') + ['build']) self.run_browser('dist/index.html', '/report_result?exit:0')