This extension allows you to register your less files and they will be compiled to CSS with the option to cache.
Copy the yii-less folder into the extensions folder of you app.
In your config file register the extension:
'behaviors'=>array(
'ext.yii-less.components.LessCompilationBehavior',
),
In your config file register your less files to precompile:
'components'=>array(
'lessCompiler'=>array(
'class'=>'ext.yii-less.components.LessCompiler',
'paths'=>array(
// you can access to the compiled file on this path
'css/bootstrap.css' => array(
'precompile' => true, // whether you want to cache the generation
'compressed' => true, // Will pass the compressed option to the less compiler - Compresses all the unrequired whitespace - Defaults to false
'paths' => array('less/bootstrap.less') //paths of less files. you can specify multiple files.
),
),
),
),
Register your asset in your layout:
Yii::app()->clientScript->registerCssFile('css/bootstrap.css')
If you are using the precompile option, it will set the expires header to 1 week. To bust the cache automatically, add a version number to the end of the file path when modifying the LESS file.
Yii::app()->clientScript->registerCssFile('css/bootstrap.css?v=1.0.1')
This extension is heavily based on Crisu83's extension: http://www.yiiframework.com/extension/less/. I changed how the configuration works so they are not compatible and that's the reason for the fork. I hope he doesn't mind.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request