4

If I define the following nested styles in LESS:

.nav-bar {
    .navbar-brand {
        background: #000;
    }
}

.nav-bar {
    .navbar-brand {
        background: #fff;
    }
}

It results in:

.nav-bar .navbar-brand {
  background: #000;
}
.nav-bar .navbar-brand {
  background: #fff;
}

I was hoping that these might be detected as duplicates. So, the result would simply be:

.nav-bar .navbar-brand {
  background: #fff;
}

.. as the first style would be overwritten. I know that the web browser would treat it as such, whereby the second styles properties would overwrite the first. I'm more concerned about file size though. I was hoping that I could download LESS for Bootstrap, then in a custom LESS file, overwrite styles for that particular project. Is this feature available by the compiler?

cimmanon
  • 67,211
  • 17
  • 165
  • 171
Martyn
  • 6,031
  • 12
  • 55
  • 121

1 Answers1

4

You should use https://github.com/less/less-plugin-clean-css with the advanced option turned on.

Run npm install less-plugin-clean-css after that you can use lessc file.less --clean-css="advanced".

With the above command:

.nav-bar {
    .navbar-brand {
        background: #000;
    }
}

.nav-bar {
    .navbar-brand {
        background: #fff;
    }
}

compiles into:

.nav-bar .navbar-brand{background:#fff}

Also see: How to keep duplicate properties in compiled CSS file when use LESS?

Community
  • 1
  • 1
Bass Jobsen
  • 48,736
  • 16
  • 143
  • 224