快速入门
概览
变量(Variables)
混入(Mixins)
嵌套(Nesting)
运算(Operations)
转义(Escaping)
函数(Functions)
命名空间和访问符
映射(Maps)
作用域(Scope)
注释(Comments)
导入(Importing)
使用 Less.js
命令行用法
浏览器使用
Less.js选项
预加载插件
程序化使用
API
为 Less.js 做贡献
Less 函数手册
逻辑函数
字符串函数
列表函数
数学函数
类型函数
杂项函数
颜色定义函数
颜色通道函数
颜色操作函数
颜色混合函数
进阶指南
变量
父选择器
继承
合并
Mixins
CSS Guards
分离规则集
@import At-Rules
@plugin At-Rules
Maps (NEW!)
作用域
程序化使用 - Less入门文档 - 笔下光年
网站首页
程序化使用
进入 less 的主要入口是 `less.render` 函数。它的格式如下 ```less less.render(lessInput, options) .then(function(output) { // output.css = string of css // output.map = string of sourcemap // output.imports = array of string filenames of the imports referenced }, function(error) { }); // or... less.render(css, options, function(error, output) {}) ``` 选项参数是可选的。如果指定了回调,则不会返回 `promise`;如果没有指定回调,则会返回 `promise`。在幕后,使用回调版本是为了同步使用 less。 如果要渲染一个文件,首先要将其读成字符串(传递给 `less.render`),然后将选项中的 `filename` 字段设置为主文件的文件名。 `sourceMap` "选项是一个可以设置子 sourcemap 选项的对象。可用的子选项有 `sourceMapURL`,`sourceMapBasepath`,`sourceMapRootpath`,`outputSourceFiles` 和 `sourceMapFileInline`。请注意,浏览器编译器中的 less.js 现在不提供 `sourceMap` 选项。 ```less less.render(lessInput) .then(function(output) { // output.css = string of css // output.map = undefined } //, less.render(lessInput, {sourceMap: {}}) .then(function(output) { // output.css = string of css // output.map = string of sourcemap } //or, less.render(lessInput, {sourceMap: {sourceMapFileInline: true}}) .then(function(output) { // output.css = string of css \n /*# sourceMappingURL=data:application/json;base64,eyJ2ZXJ..= */ // output.map = undefined } ``` ### 访问日志 您可以使用以下代码添加日志监听器 ```less less.logger.addListener({ debug: function(msg) { }, info: function(msg) { }, warn: function(msg) { }, error: function(msg) { } }); ``` **注意:** 所有函数都是可选的。错误不会被记录,而是传回给 `less.render` 中的回调或 `promise`。
上一篇:
预加载插件
下一篇:
API