English 中文(简体)
Less - Programmatic Usage
  • 时间:2024-12-22

LESS - Programmatic Usage


Previous Page Next Page  

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 sourceMapFileInpne. 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 pstener 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.

Advertisements