0

An always annoying problem i had with lessphp (and also less compiling in rails or python/django) is that it is only watching the file which to compile but NOT the imported files.

For example my less structure looks something like this:

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

.

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

So the actual compiled file is only the root to import the styles and files i work on. Everytime i make a change on my styles(theme.less) i have to edit the main.less so it gets recompiled.

Is there any option to check ALL files for changes like it does on client-side compile(less.js)?

bench-o
  • 2,339
  • 5
  • 21
  • 21

1 Answers1

0

When you inspect the source of the php lessc compiler, which can be found at https://raw.githubusercontent.com/oyejorge/less.php/master/bin/lessc, you will found that the script only evaluate the modification time of the Less file that you have passed as argument.

When you less files are in /home/project/less you can add for instance the following code inside the while(1) loop in bin/less, around line 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;
}
Bass Jobsen
  • 48,736
  • 16
  • 143
  • 224