Search code examples
cssclasslessmixinsless-mixins

Prevent Compilation of Unused LESS Class


I have a basic mixin class that I want to use in hundreds of classes

.MainContentView {
  /*blah blah blah dee dah*/
}

.WorkspaceView1 {
  .MainContentView;
  .LightTealGradientBackground;
  /* blah blah blah hoo bah*/
}

But I don't want MainContentView to show up in the compiled CSS. I just want it to be used in the various WorkspacesView(n)s. All such classes that aren't actually used in HTML, but which are used to create other classes, shouldn't show up in the compiled CSS because they're just overhead.

Surprisingly, the LESS Reference doesn't cover such an example.


Solution

  • The Less reference has this example:

    Not Outputting the Mixin

    Simply put parentheses () after the mixin:

    .MainContentView() {
      /*blah blah blah dee dah*/
    }