lessphp:也可以观看导入的文件

时间:2014-10-16 17:43:02

标签: less lessphp

我使用lessphp时遇到的一个令人讨厌的问题(在rails或python / django中的编译也较少)是它只是在查看要编译的文件而不是导入的文件。

例如,我的较少结构看起来像这样:

// main.less 
// (compiled to styles.css)
@import "variables"
@import "objects"
@import "theme"

// theme.less 
// (actual styles)
body { background:#efefef }

所以实际编译的文件只是导入我工作的样式和文件的根。每当我对我的样式(theme.less)进行更改时,我必须编辑main.less,以便重新编译。

是否有任何选项可以检查所有文件的更改,就像在客户端编译时那样(less.js)?

1 个答案:

答案 0 :(得分:0)

当您检查可以在https://raw.githubusercontent.com/oyejorge/less.php/master/bin/lessc找到的php lessc编译器的源时,您会发现该脚本仅评估您作为参数传递的Less文件的修改时间。

如果/home/project/less中的文件较少,您可以在bin / less中的while(1)循环内添加以下代码,在第125行附近:

while (1) {
    clearstatcache();
//keep original code here
$dir = '/home/project/less';
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
    if(preg_match('/\.less$/',$filename) && filemtime($filename) > $lastAction)
    {
       $updated = true;
       break;
    }
}
if($updated) break;
}