Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/rspack_plugin_wasm/src/parser_and_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{
borrow::Cow,
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
path::Path,
};

use indexmap::IndexMap;
Expand Down Expand Up @@ -261,10 +262,16 @@ impl ParserAndGenerator for AsyncWasmParserAndGenerator {
None
};

let origin_filename = Path::new(&normal_module.resource_resolved_data().resource)
.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("");

let instantiate_call = format!(
"{}(exports, module.id, {} {})",
"{}(exports, module.id, {}, {} {})",
RuntimeGlobals::INSTANTIATE_WASM,
serde_json::to_string(&hash).expect("should be ok"),
serde_json::to_string(origin_filename).expect("should be ok"),
imports_obj.unwrap_or_default()
);

Expand Down
5 changes: 3 additions & 2 deletions crates/rspack_plugin_wasm/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl RuntimeModule for AsyncWasmLoadingRuntimeModule {
.hash(&hash)
.content_hash(&hash)
.id(&PathData::prepare_id("\" + wasmModuleId + \""))
.filename("\" + wasmModuleName + \"")
.runtime(chunk.runtime().as_str()),
)
.await?;
Expand Down Expand Up @@ -109,7 +110,7 @@ fn get_async_wasm_loading(req: &str, supports_streaming: bool) -> String {
if supports_streaming {
format!(
r#"
__webpack_require__.v = function(exports, wasmModuleId, wasmModuleHash, importsObj) {{
__webpack_require__.v = function(exports, wasmModuleId, wasmModuleHash, wasmModuleName, importsObj) {{
var req = {req};
var fallback = function() {{
return req{fallback_code}
Expand All @@ -122,7 +123,7 @@ fn get_async_wasm_loading(req: &str, supports_streaming: bool) -> String {
let req = req.trim_end_matches(';');
format!(
r#"
__webpack_require__.v = function(exports, wasmModuleId, wasmModuleHash, importsObj) {{
__webpack_require__.v = function(exports, wasmModuleId, wasmModuleHash, wasmModuleName, importsObj) {{
return {req}{fallback_code}
}};
"#
Expand Down
Loading