Skip to content

Add support for CSS Modules with explicit filename #2278

Closed
@ro-savage

Description

@ro-savage

I suggest adding support for CSS Modules with an explicit filename, allowing those who wish to use CSS Modules to do so without interfering with importing regular stylesheets including from external packages.

What is CSS Modules
CSS Modules will autogenerate a classname with hash to insure scoped classnames. This means that you no longer have to worry about clashing classnames or using BEM or similar naming convention. It does this in the background when CSS is being generated.

To quote CSS Modules: No more conflicts, explicit dependencies, no global scope.

Explicit file name
[name].modules.css

Regex
CSS Module: /\.modules.css$/
Not Module: /[^\.modules]\.css$/

Reasoning
CSS Modules is widely used, has excellent satisfaction (97%) according to StateOfJS. It also allows an easy alternative with IDE support from CSSinJS solutions and wont interfere with regular css.

Opt-in only
The feature would be entirely optional and a user would have to explicitly opt in by using the naming convention and importing the css file into a JS file.

Gotchas
If someone named a stylesheet [something].modules.css without it actually being a CSS Module and imported it, it would be imported as a CSS Module.

Pull Request
PR #2285

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions