Css is awesome, but it has a lot of limitations. For example, lets say that you have 1 color that you place everywhere (brand color). If you wanted to change this color, you would either go through each css file looking for it with control+f/cmd+f or you would do a find and replace. That’s very inefficient. Less allows you to code css like a programming language. How does it work?
@myColor:blue;body{color:red;h2{color:@myColor;&:hover{text-align:center;}}p{background-color:@myColor;}}/* Compiles to */body{color:red;}bodyh2{color:blue;}bodyh2:hover{text-align:center;}bodyp{background-color:blue;}
Installation
1
2
# To install less in your express app
npm install less-middleware
1
2
3
4
5
6
7
8
9
// inside your app.jsvarlessMiddleware=require('less-middleware');app.use(lessMiddleware(__dirname+'/public'));// this order is importantapp.use(express.static(__dirname+'/public'));// Now when you create .less files, a matching .css file gets created when you save// So you can add the link to that css file in your html like you normally would and voila// example in this project folder as usual.