Fixed sass tool

This commit is contained in:
YuKun Liu committed 2022-05-10 13:46:53 +08:00
1 parent d10f9cc1e3
commit 8b06fe6059
2 files changed
+10 -10

No files matched your search

+2 -2
View File
@@ -47,10 +47,10 @@ binaryen = { wasm_opt = true }
# use sass auto will auto check sass file and build it. # use sass auto will auto check sass file and build it.
[application.tools.sass] [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 auto = true
# or you can specify some sass file -> css file # you can specify some scss file -> css file
files = [ files = [
# some sass file path # some sass file path
# this file will translate to `/css/test.css` # this file will translate to `/css/test.css`
+8 -8
View File
@@ -30,7 +30,6 @@ pub fn build(config: &CrateConfig) -> Result<()> {
.. ..
} = config; } = config;
// start to build the assets // start to build the assets
build_assets(config)?; 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. // if the sass open auto, we need auto-check the assets dir.
let asset_dir = config.asset_dir.clone(); let asset_dir = config.asset_dir.clone();
if asset_dir.is_dir() { if asset_dir.is_dir() {
for entry in walkdir::WalkDir::new(asset_dir) for entry in walkdir::WalkDir::new(&asset_dir)
.into_iter() .into_iter()
.filter_map(|e| e.ok()) .filter_map(|e| e.ok())
{ {
let temp = entry.path(); let temp = entry.path();
if temp.is_file() { if temp.is_file() {
let suffix = temp.file_name().unwrap().to_str().unwrap(); let suffix = temp.extension().unwrap().to_str().unwrap();
let suffix = suffix.split('.').collect::<Vec<&str>>();
let suffix: &str = suffix.last().unwrap();
if suffix == "scss" { if suffix == "scss" {
// if file suffix is `scss` we need transform it. // if file suffix is `scss` we need transform it.
let temp_stem = temp.file_stem().unwrap().to_str().unwrap(); let out_file =
let target_path = format!("{}.css", temp.file_stem().unwrap().to_str().unwrap());
temp.parent().unwrap().join(format!("{}.css", temp_stem)); let target_path = config
.out_dir
.join(temp.strip_prefix(&asset_dir).unwrap().parent().unwrap())
.join(out_file);
sass.call( sass.call(
"sass", "sass",
vec![temp.to_str().unwrap(), target_path.to_str().unwrap()], vec![temp.to_str().unwrap(), target_path.to_str().unwrap()],