Skip to content

Add support for custom css modules name patterns#180

Merged
devongovett merged 4 commits into
masterfrom
cssmodules-config
May 20, 2022
Merged

Add support for custom css modules name patterns#180
devongovett merged 4 commits into
masterfrom
cssmodules-config

Conversation

@devongovett

Copy link
Copy Markdown
Member

Closes #156.

This adds support for custom patterns for generating names in css modules. Using cssModules: true continues to use the same default pattern as before, but you can also now set it to a config object:

{
  cssModules: {
    pattern: 'library-[name]-[hash]-[local]
  }
}

The currently supported segments are:

  • [name] - the base name of the file name being transformed, without the extension
  • [hash] - a hash of the full file path
  • [local] - the original class name

We could add more if needed as well. The pattern is parsed ahead of time and interpreted when writing out class names. Hopefully this solves the majority of use cases. We could add a JS callback for this as well, but it would add a lot of performance overhead so I would like to avoid it if possible.

@devongovett devongovett marked this pull request as ready for review May 20, 2022 14:34
@devongovett devongovett merged commit c7a59e1 into master May 20, 2022
@devongovett devongovett deleted the cssmodules-config branch May 20, 2022 14:39
@joelmoss

Copy link
Copy Markdown
Contributor

Was this new functionality added to the rust CLI?

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.

[Feature Request] Support generateScopedName config like postcss-modules

2 participants