Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile one less-file into many css-files

Tags:

css

less

Assuming we have a main.css, which has the following content (of course, this scenario is VERY simplified):

body {
  background-color: #ffffff;
}

However, there are also themes, which have a different background-color. So we end up having five different css-files:

  • main.css
  • main_blue.css
  • main_red.css
  • main_yellow.css
  • main_green.css

But now it's really not maintainable anymore. If I have to change something in main.css, I also have to change the other files!

So I was browsing in the internet and had a glance at http://lesscss.org/ which seemed pretty promising. However, neither do I know about how I could compile one less-file into multiple css files. Nor do I know if that would be the right approach. The idea of declaring variables at the top of the css-file delights me, though.

So I wonder: Is LESS capable of solving this problem? (And if so, how?) Or are there better ways to solve this?

like image 906
Fabian Bigler Avatar asked Dec 30 '25 21:12

Fabian Bigler


1 Answers

Thanks to Harry's comment I ended up with the following solution: For each theme simply create another .less-file with the following content:

@import "main.less";
@mainbackground-color: #96c8fd;

Note that more variables will follow after the import.

like image 80
Fabian Bigler Avatar answered Jan 01 '26 11:01

Fabian Bigler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!