Skip to content

Allow named exports to have underscores in names #1206

Closed
@Finesse

Description

@Finesse
  • Operating System: macOS 10.15.6
  • Node Version: 12.18.4
  • NPM Version: 6.14.6
  • webpack Version: 4.44.2
  • css-loader Version: 4.3.0

Feature Proposal

When I set css-loader options like this:

{
    loader: 'css-loader',
    options: {
        modules: {
            namedExport: true,
            exportLocalsConvention: 'dashesOnly',
        },
    }
},

The loader emits an error for each CSS file: The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "camelCaseOnly".

I understand that class names mustn't contain dashes and many other characters to be able to be constant names, but underscore (_) is allowed and I want to use it in constant names.

In order to achieve this, there can be a value like leaveUnderscore for the exportLocalsConvention option that shall camelize everything except underscores and be accepted when namedExports is true.

Feature Use Case

BEM. Even though CSS modules make BEM be completely meaningless, underscore can be used to split logical parts in CSS class names, especially when CSS is produced by a preprocessor. For example, here is my SCSS:

.bigButton {
    &_label {
    }
}
.label {
    &_icon {
    }
}

I want to use the class names as is:

import {bigButton, bigButton_label, label, label_icon} from './style.scss?module';

Having 2 ways to split words (camelCase and under_score) is very handy for giving meaningful names to CSS items.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions