myFavShrimp / turf

Macro based compile-time SCSS transpilation, CSS minification, and class name uniquification toolchain inspired by CSS modules.
MIT License
50 stars 2 forks source link

Styles don't get updated #3

Closed xYouLL closed 1 year ago

xYouLL commented 1 year ago

Hello, I'm currently trying turf with Leptos. I'm facing some issues while on trunk serve --open, everytime I try to edit an existing style it doesn't get updated even if I stop the ongoing serve and start again and also if I try to delete the cache by CTRL + F5. It just gets updated randomly, without any criteria from what I see.

Turf version: 0.4.0 Leptos version: 0.4.4 (features: csr, nightly) Leptos router version 0.4.4 (features: csr)

myFavShrimp commented 1 year ago

Hey, thanks for reporting the issue. I have also noticed this problem lately and came up with a solution.

You need to create a build.rs build script file in your project root (right next to your src directory). In the build.rs you put the following content:

fn main() {
    // Tell Cargo that if the given file changes, to rerun this build script.
    println!("cargo:rerun-if-changed=src/**/*.scss");
}

src is the directory containing your SCSS files. You may need to change this path according to your project setup.

Sadly, there seems to be no other way currently as this is a limitation of Rust itself. I'm still in the process of thinking about a proper way to handle this but I will document this build script solution in turf's README and example projects.

Thanks again for posting the issue. Please let me know if this solved the problem for you :slightly_smiling_face:

wrapperup commented 1 year ago

Sadly, there seems to be no other way currently as this is a limitation of Rust itself. I'm still in the process of thinking about a proper way to handle this but I will document this build script solution in turf's README and example projects.

Currently, the tracked path API is a thing, but nightly only. A trick Askama uses to track files right in the macro in stable is by using include_bytes!, but not actually using it. See here

myFavShrimp commented 1 year ago

A trick Askama uses to track files right in the macro in stable is by using include_bytes!, but not actually using it.

Thanks for pointing out this trick. Using include_bytes is clever. I personally like to have more consistent behavior so I'd favor a solution that makes tracking files included using the load_paths setting possible too. I will experiment a little with it (e.g. for using it for the load_paths files as well).

myFavShrimp commented 1 year ago

Good news! I implemented a first draft of the include_bytes file tracking and it works for load_paths files as well. I have to make some changes to how the file paths are handled by turf before this can land on main as the include_bytes macro assumes paths to be relative to the current file's directory while everything else in turf needs them to be relative to Cargo's current working directory.

myFavShrimp commented 1 year ago

The necessary changes have been made and are included in the latest 0.6.0 release.