From ae0512eab96c55a29e0a1ffc755d34ab19f89fbf Mon Sep 17 00:00:00 2001 From: Cong-Cong Date: Wed, 30 Oct 2024 17:16:27 +0800 Subject: [PATCH] fix --- .../src/source_map_dev_tool_plugin.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/rspack_plugin_devtool/src/source_map_dev_tool_plugin.rs b/crates/rspack_plugin_devtool/src/source_map_dev_tool_plugin.rs index aa02c2f16ad1..0629a8f49a43 100644 --- a/crates/rspack_plugin_devtool/src/source_map_dev_tool_plugin.rs +++ b/crates/rspack_plugin_devtool/src/source_map_dev_tool_plugin.rs @@ -1,3 +1,4 @@ +use std::path::{Component, PathBuf}; use std::sync::LazyLock; use std::{borrow::Cow, path::Path}; @@ -417,12 +418,18 @@ impl SourceMapDevToolPlugin { let source_map_url = if let Some(public_path) = &self.public_path { format!("{public_path}{source_map_filename}") } else { + let mut file_path = PathBuf::new(); + file_path.push(Component::RootDir); + file_path.extend(Path::new(filename.as_ref()).components()); + + let mut source_map_path = PathBuf::new(); + source_map_path.push(Component::RootDir); + source_map_path.extend(Path::new(&source_map_filename).components()); + relative( #[allow(clippy::unwrap_used)] - &Path::new(&format!("/{}", filename.as_ref())) - .parent() - .unwrap(), - &Path::new(&format!("/{}", &source_map_filename)), + file_path.parent().unwrap(), + &source_map_path, ) .to_string_lossy() .to_string()