yiisoft / yii

Yii PHP Framework 1.1.x
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
4.85k stars 2.28k forks source link

LESS support proposal #3399

Closed Kolyunya closed 10 years ago

Kolyunya commented 10 years ago

I would like to propose adding LESS support to the framework. LESS files sould be declared with 'stylesheet/less' relation. This feature may be easily implemented by modifying CHtml::cssFile like this (or something more performant) This will even allow registering LESS files through CClientScript like regular CSS files since it uses CHtml.

public static function cssFile($url,$media='')
{
        $relation = preg_match('/\.less$/',$url) ? 'stylesheet/less' : 'stylesheet';
        return CHtml::linkTag($relation,'text/css',$url,$media!=='' ? $media : null);
}
samdark commented 10 years ago

It is already supported via asset manager.

cebe commented 10 years ago

@Kolyunya client side less files are very slow as the less has to be parsed for every request in the browser so you should not do this. always compile less files on the server.

Kolyunya commented 10 years ago

@samdark I am sorry, but I think you missunderstood the proposal which is to allow LESS files be registered via CClientScript like this.

Yii::app()->clientScript->registerCssFile('foo.less');

The above code should render a link to the less file with 'stylesheet/less' relation.

@samdark could you please elaborate what is actually supported by asset manager?

samdark commented 10 years ago

By asset manager I've meant Yii 2.0. For 1.1 it's not supported but as @cebe mentioned, it's a very bad practice to use JavaScript-based less compiler. It is extremely slow.