Skip to content

Dropping empty classes #269

Open
Open

Description

@juanca

Just had a thought recently that I think might align / help CSS modules:

Should CSS modules drop empty classes?

Motivation

Some of my stylesheets are strictly related to specific components. These stylesheets only compose from our design system.

.container {
  composes: field field-rounded field-editable from 'styleguide/field.css';
}

Problem

The component gets 4 classes applied but one of them is useless.

<input class="foo-container-123 styleguide-field-123 styleguide-field-rounded-123 styleguide-field-editable-123" />

Out of convenience, it would be neat to avoid exporting a class name which has no rules.

Just wanted to share this thought and get feedback.

Activity

  1. roblevintennis commented on Oct 27, 2017

    @roblevintennis

    I'm actually seeing similar type of thing but when I use composes:

    image

    So for every composed class, I get an additional empty class. I see from the readme you guys mention:

    When a class name composes another class name, the CSS Module exports both class names for the local class. This can add up to multiple class names.

    But it's a bit surprising to see all the extra classes as an application developer and initially made me think I was doing something wrong.

    This was similarly for composes like the following classes:

    .c8 {
        composes: c8 from 'styleguide/layout/flex-row/_flex-row.scss';
    }
    .b1 {
        composes: b1 from 'styleguide/layout/flex-row/_flex-row.scss';
    }
    .a1 {
        composes: a1 from 'styleguide/layout/flex-row/_flex-row.scss';
    }
    
  2. shepmaster commented on Mar 30, 2018

    @shepmaster

    Seems to be a duplicate of #127.

  3. bitttttten commented on Jul 28, 2018

    @bitttttten

    You can use minimize: true in the css-loader options which will remove the class from the CSS, but it does not remove the class from the DOM.

  4. added 2 commits that reference this issue on May 9, 2021
    dec5b56
    91954d8
  5. added a commit that references this issue on Jun 9, 2021
    9c23834
  6. tamer-flaconi commented on Jan 24, 2023

    @tamer-flaconi

    any updates on this?

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

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