LESS - Programmatic Usage


Advertisements

The main point of programmatic usage in the LESS is less.render function. This function uses the following format in LESS −

less.render(input_data, options)
.then(function(output) {
   //code here
},
   
function(error) {
});

the function can also be written in the following way −

less.render(css, options, function(error, output) {})

The options is an optional argument which returns a promise when you don't specify the callback and returns a promise when you specify the callback. You can display the file by reading it into string and set the filename fields of the main file.

The sourceMap option allows to set sourcemap options such as sourceMapURL, sourceMapBasepath, sourceMapRootpath, outputSourceFiles and sourceMapFileInline. The point that needs to be considered here is that the sourceMap option is not available for the less.js.

You can gain access to the log by adding a listener as shown in the below format −

less.logger.addListener({
   debug: function(message) {
   },
   
   info: function(message) {
   },
   
   warn: function(message) {
   },
   
   error: function(message) {
   }
});

The above defined functions are optional. If an error is displayed, then it will pass the error to callback or promise present in the less.render.

Useful Video Courses


Video

LESS Online Training

20 Lectures 1 hours

Anadi Sharma

Video

Serverless Development with AWS Lambda and NodeJS

44 Lectures 7.5 hours

Eduonix Learning Solutions

Video

Delegation Mastery: Learn to Outsource Your Work and Do Less

17 Lectures 2 hours

Zach Miller

Video

Create a WordPress Website in 24 Hours or Less Guaranteed

23 Lectures 1.5 hours

Zach Miller

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

AWS LAMBDA- Serverless Computing

31 Lectures 3 hours

Harshit Srivastava

Advertisements