Skip to content

feat: add deterministic local CSS naming option - #4391

Open
joelmoss wants to merge 1 commit into
evanw:mainfrom
joelmoss:deterministic_local_css_names
Open

feat: add deterministic local CSS naming option#4391
joelmoss wants to merge 1 commit into
evanw:mainfrom
joelmoss:deterministic_local_css_names

Conversation

@joelmoss

Copy link
Copy Markdown

This feature introduces a new option DeterministicLocalCSSNaming that, when true, ensures that local CSS class names are generated in a deterministic manner. This is particularly useful for caching and consistent builds across different environments.

When MinifyIdentifiers is enabled, the local name is generated as the original CSS class name, and a hash of the absolute source file path, separated by an underscore (eg. <original-class-name>_<hash-of-absolute-path>).

When MinifyIdentifiers is disabled, the local name is appended with a CSS safe version of the relative source file path (eg.
<original-class-name>_<hash-of-absolute-path>_<relative-source-file-path>) to aid in development.

May address #3484?

@joelmoss
joelmoss force-pushed the deterministic_local_css_names branch from bfb4a1d to a250fe6 Compare February 12, 2026 18:21
This feature introduces a new option `DeterministicLocalCSSNaming` that, when true, ensures that
local CSS class names are generated in a deterministic manner. This is particularly useful for
caching and consistent builds across different environments.

When `MinifyIdentifiers` is enabled, the local name is generated as the original CSS class name, and
a hash of the absolute source file path, separated by an underscore (eg.
`<original-class-name>_<hash-of-absolute-path>`).

When `MinifyIdentifiers` is disabled, the local name is appended with a CSS safe version of the
relative source file path (eg.
`<original-class-name>_<hash-of-absolute-path>_<relative-source-file-path>`) to aid in development.
@joelmoss
joelmoss force-pushed the deterministic_local_css_names branch from a250fe6 to 9886767 Compare February 12, 2026 18:34
@mhsdesign

Copy link
Copy Markdown

Hi thank you! using a hash would fix my problem from #3484 indeed if the hash contains the package name of the npm package which it does due to the absolute path.

Now i have a question: As this change attempts to make bundles deterministic that two setups produce the same minified code, isnt it counterproductive to have the full absolute path being used for building the hash? Especially when people do not use a standardised docker container where their source code resides on the exact same path but work locally? Can we instead use some kind of relative path + if applicable the npm package name?

@joelmoss

Copy link
Copy Markdown
Author

The absolute path is used, because sometimes assets are located outside of the project. In which case, relative paths will not work.

@mhsdesign

Copy link
Copy Markdown

paths could still be calculated via relative traversal ../../../some/outside.css

@joelmoss

Copy link
Copy Markdown
Author

Yes, but then you may as well use absolute paths, and they are more readable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants