diff --git a/packages/cli/src/build/builder.rs b/packages/cli/src/build/builder.rs index 5ea225f51..79c2b9af2 100644 --- a/packages/cli/src/build/builder.rs +++ b/packages/cli/src/build/builder.rs @@ -521,7 +521,7 @@ impl AppBuilder { envs.push(("RUST_BACKTRACE".into(), "1".to_string())); } - if let Some(base_path) = krate.base_path() { + if let Some(base_path) = krate.trimmed_base_path() { envs.push(( dioxus_cli_config::ASSET_ROOT_ENV.into(), base_path.to_string(), diff --git a/packages/cli/src/build/request.rs b/packages/cli/src/build/request.rs index bbdccd944..ab363fc4c 100644 --- a/packages/cli/src/build/request.rs +++ b/packages/cli/src/build/request.rs @@ -2801,7 +2801,7 @@ impl BuildRequest { // If this is a release build, bake the base path and title into the binary with env vars. // todo: should we even be doing this? might be better being a build.rs or something else. if self.release { - if let Some(base_path) = self.base_path() { + if let Some(base_path) = self.trimmed_base_path() { env_vars.push((ASSET_ROOT_ENV.into(), base_path.to_string().into())); } env_vars.push(( @@ -4898,7 +4898,7 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{ // Add the base path to the head if this is a debug build if self.is_dev_build() { - if let Some(base_path) = &self.base_path() { + if let Some(base_path) = &self.trimmed_base_path() { head_resources.push_str(&format_base_path_meta_element(base_path)); } } @@ -5044,14 +5044,16 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{ .filter(|_| matches!(self.bundle, BundleFormat::Web | BundleFormat::Server)) } - /// Get the normalized base path for the application with `/` trimmed from both ends. If the base path is not set, this will return `.`. + /// Get the normalized base path for the application with `/` trimmed from both ends. + pub(crate) fn trimmed_base_path(&self) -> Option<&str> { + self.base_path() + .map(|p| p.trim_matches('/')) + .filter(|p| !p.is_empty()) + } + + /// Get the trimmed base path or `.` if no base path is set pub(crate) fn base_path_or_default(&self) -> &str { - let trimmed_path = self.base_path().unwrap_or_default().trim_matches('/'); - if trimmed_path.is_empty() { - "." - } else { - trimmed_path - } + self.trimmed_base_path().unwrap_or(".") } /// Get the path to the package manifest directory