parcel-bundler / lightningcss

An extremely fast CSS parser, transformer, bundler, and minifier written in Rust.
https://lightningcss.dev
Mozilla Public License 2.0
6.14k stars 167 forks source link

Match CSS modules hashing with PostCSS #636

Open marvinhagemeister opened 7 months ago

marvinhagemeister commented 7 months ago

I'm currently exploring adding support for CSS Modules natively in Deno via lightningcss. In doing so I noticed that the hash segment is a different value then the one calculated by PostCSS. It seems like PostCSS is using a hex digest of the xxhash64 hash of the root relative file path compared to lightningcss which uses rust's default SipHash-1-3 algorithm.

To make native CSS Modules support in Deno useful, the hash value needs to match whatever users may be using to generate browser bundles with. Would folks be open to the idea to change the hashing function here to match the one from PostCSS? I'd be happy to make a PR for that.

devongovett commented 6 months ago

Why would the exact hash matter? Isn't the point of hashing css modules so that they contain an unpredictable value that won't conflict?

SevereCloud commented 4 months ago

For example, to use with https://github.com/VKCOM/swc-plugin-css-modules

mayank99 commented 3 months ago

Rather than lightningcss changing the internal hash function, it might be better to allow customizing the hash, so that Deno can do it in userland.

See #491 and #503