Sfoglia il codice sorgente

Add `files` list option

YuKun Liu 3 anni fa
parent
commit
b5ecd09185
2 ha cambiato i file con 23 aggiunte e 1 eliminazioni
  1. 1 1
      src/assets/dioxus.toml
  2. 22 0
      src/builder.rs

+ 1 - 1
src/assets/dioxus.toml

@@ -50,7 +50,7 @@ binaryen = { wasm_opt = true }
 # auto will check the assets dirs, and auto to transform all scss file to css file.
 auto = true
 
-# you can specify some scss file -> css file
+# or you can specify some scss file -> css file
 files = [
     # some sass file path
     # this file will translate to `/css/test.css`

+ 22 - 0
src/builder.rs

@@ -381,6 +381,28 @@ fn build_assets(config: &CrateConfig) -> Result<()> {
                         }
                     }
                 }
+            } else if tab.contains_key("files") && tab.get("files").unwrap().is_array() {
+                // check files list.
+                let list = tab.get("files").unwrap().as_array().unwrap();
+                for i in list {
+                    if i.is_str() {
+                        let path = i.as_str().unwrap();
+                        let path = PathBuf::from(path);
+                        let path = config.asset_dir.join(path);
+                        if path.is_file() {
+                            sass.call(
+                                "sass",
+                                vec![
+                                    path.to_str().unwrap(),
+                                    path.parent().unwrap().join(format!(
+                                        "{}.css",
+                                        path.file_stem().unwrap().to_str().unwrap()
+                                    )).to_str().unwrap(),
+                                ],
+                            )?;
+                        }
+                    }
+                }
             }
         }
     }