myFavShrimp / turf

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

Hashes in `class_names.template` config #23

Closed lukidoescode closed 2 weeks ago

lukidoescode commented 1 month ago

What

This PR introduces four new placeholders into the template config:

Why

I found the file output feature of turf to be quite unusable, because the IDs generated by the <id> template placeholder would change upon every visit. That means that when using the <id> placeholder, the <id> generated in the output file would not match the <id> returned by the macro for use in e.g. my leptos code.

That's why I felt the need to introduce a deterministic and obfuscated differentiator for the source file names, as well as for the class names. This allows the same class name, e.g. .container, in multiple files. The <id> achieves the same result, but not in a deterministic manner.

The reason for adding short versions is because it is the web and size does matter.

Seeing is believing

Screenshot 2024-09-18 at 22 49 54
lukidoescode commented 1 month ago

Please don't be scared of the amount of changes. Most of it comes from copying and slightly modifying an example. And from all the changes in the lock files.

Also, please squash merge. I imagine my commit messages would otherwise be pretty nonsensical.

lukidoescode commented 1 month ago

Sorry, I had to make some updates after having used this directly from git in my own project.

I also increased the density of the hashes by base64 encoding them, instead of the previous hex encoding with its limited alphabet. Just to make using the short hashes more feasible by avoiding possible collisions.

myFavShrimp commented 1 month ago

Thank you very much for creating the pr! I will review it within the next few days when find some free time

myFavShrimp commented 1 week ago

I created a new release 0.9.4 which includes your changes. Thank you very much again for your contribution!

lukidoescode commented 1 week ago

Thanks for merging! It was my pleasure!