privatenumber / vite-css-modules

Vite plugin for correct CSS Modules behavior
MIT License
50 stars 2 forks source link

Support css modules without .module.css extension #12

Open myshov opened 1 week ago

myshov commented 1 week ago

Feature request

Currently vite supports css modules that have .module.css file extension, it would be useful to add possibility to costumize extension via plugin option

Motivations

In our project we sometimes have quite long file names for css files, so replacing it with extension .module.css is not an ideal solution. So it would be nice to tweak this setting with additional option. Someting like this:

    patchCssModules({fileExtension: '.css'}),

Alternatives

As a workaround I am trying to use this plugin https://github.com/Summer-andy/vite-plugin-transform-css-modules but it doesn't work with vite-css-modules

Additional context

No response

Bugs are expected to be fixed by those affected by it

Compensating engineering work financially will speed up resolution

privatenumber commented 1 week ago

The .module.css convention is important for keeping code predictable. It signals to the bundler whether to handle a file as a CSS Module or a global style, making it easier to manage different CSS uses within an application. Sticking to this convention also simplifies future migrations between bundlers by providing a clear, consistent standard.

That said, I support making this configurable with sensible defaults, so I'm open to a pull request to add this flexibility. I'd also recommend submitting a feature request in Vite's repo to ensure alignment.

For implementation, we could follow Vite/Rollup's convention with include/exclude patterns and set **/*.module.css as the default include.