pub fn resolve_path(file: &str, path: &str) -> StringExpand description
Experimental utility for resolving the manifest path.
§Arguments
file- the current script file path (obtained withfile!()macro);path- the “path/to/manifest.json” string slice.
§Panics
This function might panic in various occasions:
- if
filehas no parent directory (e.g. “src/main.rs” parent would be “src”); - if it fails to find the
filefirst segment somehow (e.g. “path/to/file” => “path”); - if the first file path
Componentis neitherRootDirnorNormal; - if final result fails to be canonicalized.
The last situation might occur if the final path doesn’t really lead to any existing file/directory. Or perhaps, because this function has a bug! In this case, please open an issue at our GitHub repository!
§Example
example/
|-- .dist/
| |-- .vite/
| | |-- manifest.json
|-- src/
| |-- main.rsⓘ
// example/src/main.rs
let manifest_path = resolve_path(file!(), "../dist/.vite/manifest.json");
let mut vite_config = ViteConfig::new_with_defaults(&manifest_path);
println!("{manifest_path}");
// C:/totally/absolute/path/to/example/.dist/.vite/manifest.json