解析LESS客户端 [英] Parse LESS client side

查看:148
本文介绍了解析LESS客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以解析LESS客户端,并返回结果吗?

Can I parse LESS client side, and return the results?

我目前正在按照文档中的建议使用,这是包括更少的文件,之后。我想要能够返回原始css,所以我可以将其保存为一个css文件。

I am currently using as recommended in documentation, which is to include less file, and minified less parser afterwards. I want to be able to return the raw css so I can save it as a css file.

我不想安装node.js和喜欢,我想客户端解决方案。

I do not want to install node.js and the likes, I want a client side solution.

推荐答案

查看 less.js source 调出 Parser 对象。假设 less.js 包含在页面中:

A look at the less.js source brings up the Parser object. Assuming that less.js is included in the page:

var data = "@colour: red; #example { background-color: @colour; }",
    parser = new less.Parser({});

parser.parse(data, function (error, root) { 
    // code that handles the parsed data here...
    // e.g.:
    console.log( root.toCSS() ); 
});

会将以下内容输出到控制台:

will output the following to the console:

#example {
  background-color: #ff0000;
}

less.Parser 实际上采取一系列的设置,我不太明白LESS的内部,说什么可能是好的传递(虽然他们都是可选的,所以传递none应该只使用默认值)。

The constructor for less.Parser actually takes series of settings, and I don't understand enough of the internals of LESS to say what might be good to pass (though they are all optional so passing none should just use the defaults).

Parser.parse 方法有两个参数:一个包含LESS文件的字符串,解析数据。回调最多接收两个参数,一个错误对象(错误)和一个表示解析的LESS( root ) 。如果发生致命错误, root 不会传递,错误将会 null 如果没有错误。

The Parser.parse method takes two parameters: a string containing the LESS file, and a callback that handles the parsed data. The callback receives up to two parameters, an error object (error) and an object representing the parsed LESS (root). root isn't passed if there was a fatal error, and error will be null if there was no error.

不幸的是,我找不到任何更好的文档的错误参数的属性,在源此处

Unfortunately, I can't find any better documentation on the attributes of the error parameter than the place they are set in the source here.

这篇关于解析LESS客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆