From 8b06fe60596371118e47ef71a72627044c17672a Mon Sep 17 00:00:00 2001 From: YuKun Liu <41265098+mrxiaozhuox@users.noreply.github.com> Date: Tue, 10 May 2022 13:46:53 +0800 Subject: [PATCH] Fixed sass tool --- src/assets/dioxus.toml | 4 ++-- src/builder.rs | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/assets/dioxus.toml b/src/assets/dioxus.toml index 3e82e0c93..105251aa1 100644 --- a/src/assets/dioxus.toml +++ b/src/assets/dioxus.toml @@ -47,10 +47,10 @@ binaryen = { wasm_opt = true } # use sass auto will auto check sass file and build it. [application.tools.sass] -# if auto = true, we will check style array, and translate all sass file to css. +# auto will check the assets dirs, and auto to transform all scss file to css file. auto = true -# or you can specify some sass file -> css file +# you can specify some scss file -> css file files = [ # some sass file path # this file will translate to `/css/test.css` diff --git a/src/builder.rs b/src/builder.rs index 7c3a7e9fb..0e0cf7e9a 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -30,7 +30,6 @@ pub fn build(config: &CrateConfig) -> Result<()> { .. } = config; - // start to build the assets build_assets(config)?; @@ -359,20 +358,21 @@ fn build_assets(config: &CrateConfig) -> Result<()> { // if the sass open auto, we need auto-check the assets dir. let asset_dir = config.asset_dir.clone(); if asset_dir.is_dir() { - for entry in walkdir::WalkDir::new(asset_dir) + for entry in walkdir::WalkDir::new(&asset_dir) .into_iter() .filter_map(|e| e.ok()) { let temp = entry.path(); if temp.is_file() { - let suffix = temp.file_name().unwrap().to_str().unwrap(); - let suffix = suffix.split('.').collect::>(); - let suffix: &str = suffix.last().unwrap(); + let suffix = temp.extension().unwrap().to_str().unwrap(); if suffix == "scss" { // if file suffix is `scss` we need transform it. - let temp_stem = temp.file_stem().unwrap().to_str().unwrap(); - let target_path = - temp.parent().unwrap().join(format!("{}.css", temp_stem)); + let out_file = + format!("{}.css", temp.file_stem().unwrap().to_str().unwrap()); + let target_path = config + .out_dir + .join(temp.strip_prefix(&asset_dir).unwrap().parent().unwrap()) + .join(out_file); sass.call( "sass", vec![temp.to_str().unwrap(), target_path.to_str().unwrap()],