Less 程序化使用

LESS中程序化使用的要点是 less.render 函数。 此函数在LESS中使用以下格式:

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


或者你可以用另一种方式写:

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


options 是一个可选参数,当您不指定回调时返回promise,并在指定回调时返回promise。 您可以通过将其读入字符串并设置主文件的文件名字段来显示文件。


sourceMap 选项允许设置sourcemap选项,例如 sourceMapURL sourceMapBasepath sourceMapRootpath outputSourceFiles i>和 sourceMapFileInline 重要的是, sourceMap 选项不适用于less.js.


您可以通过添加侦听器来访问日志,如下面的格式所示:

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

上述定义的函数是可选的。 如果它显示错误,那么它会将错误传递给 less.render 中的回调或promise。


作者:terry,如若转载,请注明出处:https://www.web176.com/less/17544.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2023年4月26日
下一篇 2023年4月26日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注