crisu83 / yii-less
为 Yii PHP 框架提供的 LESS 编译器。
v2.0.2
2013-08-25 16:56 UTC
README
Less 是一个 Yii PHP 框架的扩展,允许开发者使用原生的 JavaScript 编译器将 LESS 文件编译成 CSS。LESS 可以通过 less.js 在客户端编译,也可以通过 lessc 在服务器端编译。Less 包含两个编译器,一个使用 less.js 的客户端编译器和一个使用 lessc 的服务器编译器。
要求
鸣谢
感谢我的朋友 Sam Stenvall (negge) 为我提供了他的服务器端编译器版本。
使用方法
设置
下载最新版本,解压扩展到 protected/extensions/less 目录下,并将所需的组件(客户端或服务器端)添加到您的应用程序配置中。以下提供了两个编译器的示例配置。
组件加载后,所有指定的 LESS 文件将被编译(只要它们已更改或启用 forceCompile),这使得它是一个预加载的好候选者。注册生成的 CSS 文件在您的布局中由您决定。
客户端
return array( 'components'=>array( ..... 'less'=>array( 'class'=>'ext.less.components.LessClientCompiler', 'files'=>array( 'less/styles.less'=>'css/styles.css', ), ), ), );
服务器端
为了在服务器端编译您的 LESS,您需要下载并安装 Node.js。安装 Node.js 后,使用 npm(Node 包管理器)安装 less 模块。
return array( 'components'=>array( 'less'=>array( 'class'=>'ext.less.components.LessServerCompiler', 'files'=>array( 'less/styles.less'=>'css/styles.css', ), 'nodePath'=>'path/to/node.exe', 'compilerPath'=>'path/to/lessc', ), ), );
配置
以下列出了每个编译器可用的配置列表(带默认值)。
客户端
'less'=>array( 'class'=>'ext.less.components.LessClientCompiler', 'files'=>array( // files to compile (relative from your base path) 'less/styles.less'=>'css/styles.css', ), 'env'=>'production', // compiler environment, either production or development 'async'=>false, // load imports asynchronous? 'fileAsync'=>false, // load imports asynchronous when in a page under a file protocol 'poll'=>1000, // when in watch mode, time in ms between polls 'dumpLineNumbers'=>'mediaQuery', // enables debugging, set to comments, mediaQuery or all 'watch'=>true, // enable watch mode? ),
服务器端
'less'=>array( 'class'=>'ext.less.components.LessServerCompiler', 'files'=>array( // files to compile (relative from your base path) 'less/styles.less'=>'css/styles.css', ), 'basePath'=>'path/to/webroot', // base path, defaults to webroot 'nodePath'=>'path/to/node.exe', // absolute path to nodejs executable 'compilerPath'=>'path/to/lessc', // absolute path to lessc 'strictImports'=>false, // force evaluation of imports? 'compression'=>false, // enable compression, either whitespace or yui 'optimizationLevel'=>false, // parser optimization level, set to 0, 1 or 2 'forceCompile'=>false, // compile files on each request? ),