less.js README

The project's README from github.com/less/less.js. As one markdown file: README.md.

Github Actions CI Downloads Twitter Follow

This is the Less.js monorepo.

More information

For general information on the language, configuration options or usage visit lesscss.org.

Here are other resources for using Less.js:

Contributing

Please read CONTRIBUTING.md. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Reporting Issues

Before opening any issue, please search for existing issues and read the Issue Guidelines, written by Nicolas Gallagher. After that if you find a bug or would like to make feature request, please open a new issue.

Please report documentation issues in the documentation project.

Development

Read Developing Less.

Release History

See the changelog

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Matthew Dean
Matthew Dean

💻 📖 🚧 📆
Alexis Sellier
Alexis Sellier

💻 📖
Luke Page
Luke Page

💻
Max Mikhailov
Max Mikhailov

💻
Lei Chen
Lei Chen

💻 🐛 📖
Daniel Puckowski
Daniel Puckowski

💻 🐛
Add your contributions

License

Copyright (c) 2009-2025 Alexis Sellier & The Core Less Team Licensed under the Apache License.

less.js (less/less.js)

Searching Database…

这是什么东西?Less 是一种动态样式表语言,在 CSS 的基础上增加了变量、混合(mixin)、嵌套和函数;Less.js 则是用 JavaScript 编写的官方编译器。这个仓库就是 Less.js 的 monorepo。
也就是说我写 .less 文件,然后得到 CSS——它是以什么形式发布的?所有东西都在一个项目里:你写 .less 文件,Less.js 把它们编译成普通的 CSS。它以 npm 包的形式发布,既可以在命令行里使用,也可以作为 JavaScript 库来调用,编译器本身位于这个 monorepo 的 packages/less 包中。
怎么让它开始编译我的样式?先用 npm 安装编译器(npm install -g less),然后运行 lessc styles.less styles.css;也可以把 less.js 直接放进网页里,让它在浏览器中编译样式。用法和配置选项在 lesscss.org 上有文档说明。
在运行它之前,我的电脑上需要装什么?只需要 Node.js 和 npm——Less.js 是用 JavaScript 写的,不需要 Python、原生编译或其他运行环境。浏览器版本更是只要一个 script 标签就行。
我应该是在浏览器里编译样式,还是在构建阶段编译?在浏览器里编译确实是一种可用的模式,但那样每次加载页面都要带上编译器并在运行时转换样式,所以正式项目会在构建阶段把 .less 预编译成 .css。另外要注意,这个仓库的 readme 是面向贡献者的;日常使用文档在 lesscss.org 上。
如今的网页开发者为什么选 Less 而不是纯 CSS?为了获得更强大的编写能力,同时最终输出的是标准 CSS:在你已经熟悉的语法之上加上变量、混合(mixin)、嵌套和函数,而且由于 Less 向后兼容 CSS,你现有的样式表可以直接照用。
这个编译器能在 Windows 和 macOS 上跑吗,还是只能在 Linux 上用?它就是一个普通的 npm 包,所以只要 Node.js 能运行的地方它都能运行——Windows、macOS 和 Linux 都可以;浏览器模式则与操作系统无关,任何现代浏览器都能用。
我可以把它用在商业项目里吗?可以——Less.js 采用 Apache 许可证(Apache-2.0)发布,只要保留许可证声明,就允许商业和闭源使用。
Less 在 CSS 的基础上增加了什么?变量、混合(mixin,即可复用的声明块)、嵌套规则、运算符,以及用于颜色和数学计算的内置函数——这些都会被 Less.js 编译掉,浏览器最终看到的只有标准 CSS。
Less 和 Sass 比怎么样?两者都是成熟的 CSS 预处理器。Less 的语法最接近纯 CSS,而且是用 JavaScript 写的,所以它既能在 Node 构建中运行,也能直接在浏览器里运行;Sass 则有自己的功能集和工具链。
这个 monorepo 里都有什么?主要的编译器包在 packages/less 里,附带自己的测试套件(npm test)、ESLint 代码检查,以及发布版本的脚本。语言文档则单独放在 lesscss.org。
Less 还在积极维护吗?是的——它从 2010 年 2 月开始开发至今,拥有大约 17,000 个 star,而且仓库显示目前仍有活跃迹象:版权声明更新到 2025 年,有用于 CI 和发布的 GitHub Actions 工作流,更新日志也在持续维护。
Creator
less
Size
17.7 MB
Stars
17K
Age
16y
Commits · 90 Days