2012-11-28 45 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調用應該處理較少的文件已被修改,並編譯它們,如上所示,這是由擴展自動完成的。