2012-11-28 47 views
0

我有这样的:当你使用Less时,“forcecompile”对YII意味着什么?

'components'=>array(
    'less'=>array(
    'class'=>'ext.less.components.LessCompiler', 
    'forceCompile'=> true, //YII_DEBUG, // indicates whether to force compiling 
    //'compress'=>false, // indicates whether to compress compiled CSS 
    //'debug'=>false, // indicates whether to enable compiler debugging mode 
    'paths'=>array(
     'less/style.less'=>'css/style.css', 
    ), 
), 

如果我能forceCompile我的网站是非常缓慢的。我会想象,因为它重新生成每个页面加载的CSS。我的问题是关于禁用它。如果我禁用它:

  1. 是否对style.less做出的任何更改都不反映在浏览器中?
  2. 如果是这样,Less的意义是什么?当然,它实际上不能用于生产呢?或者你是否禁用了forceCompile,所以它只会生成一次?

任何清晰的forcecompile将不胜感激!

(是的,我看了所有的清楚的解释...我最好能找到的是this)。

+0

少点,少点语言或少扩展? –

+0

两者。少扩展实现更少?你为什么要问? (想想我错过了你的问题的关键....) – coderama

+0

少郎,绝对是在生产中也使用。分机是你的选择 –

回答

1

首先让我告诉你什么是less点:

  1. 少是meta language,所以笼统地使用较少的帮助你编写易于维护的CSS,虽然“语言”使用的语法较少。作为一个常见示例,您可以根据其他语句将更少的变量定义为编译为css值的变量。或者,您可以像使用支持OOP的大多数其他语言一样使用混合,嵌套和继承概念。

  2. 所以你写的可以理解的,可读伪/ CSS元代码是在编译时转换为实际的CSS。


现在扩展:

即使禁用forceCompile,在style.less所做的更改应反映,因为延伸检查,如果该文件被修改(从以下几行LessCompiler.php应该说服你的事情):

if ($this->forceCompile || $this->hasChanges()) 
    $this->compileAll(); 

// ... 

/** 
* Returns whether any of files configured to be compiled has changed. 
* @return boolean the result. 
*/ 
protected function hasChanges() { 
    // ... 
     $compiled = $this->getLastModified($destination); 
    // ... 
     $modified = $this->getLastModified($dir); 
    // ... 
} 

/** 
* Returns the last modified for a specific path. 
* @param string $path the path. 
* @return integer the last modified (as a timestamp). 
*/ 
protected function getLastModified($path){ 
    //... 
} 

因此,forceCompile将始终编译您在paths中指定的文件,并且不应在生产中启用它。 hasChanges调用应该处理较少的文件已被修改,并编译它们,如上所示,这是由扩展自动完成的。