Friday, March 3, 2017

Less - Programmatic Usage

The main point of programmatic usage in the LESS is less.render function. This function uses below format in LESS:
less.render(input_data, options)
    .then(function(output) {
        //code here
    },
    function(error) {
    });
or you can write in the other way as:
less.render(css, options, function(error, output) {})
The options is a 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. Important point is that the sourceMap option is not available for the less.js.
You can 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 it dipslays an error, then it will pass the error to callback or promise present in the less.render.

No comments:

Post a Comment