【问题标题】:Telling lessphp that i have to check a folder not only a single file to refresh the output.css?告诉lessphp我必须检查一个文件夹而不仅仅是一个文件来刷新output.css?
【发布时间】:2015-04-14 11:37:53
【问题描述】:

我在这个代码中包含了lessphp:

require_once(__DIR__.'/less/lessc.inc.php');
$less = new lessc;
$less->checkedCompile(__DIR__."/less/style.less", __DIR__."/css/style.css");

但是因为我在 style.less 中包含了一些其他的 less 文件,所以每次对任何导入的 less 文件进行任何更改后,我都必须删除我看到更改的 output.css...任何人都知道我怎么知道脚本,他必须“少”检查整个文件夹是否有任何更改?

请帮我解释一下..我的英语很糟糕,我对php一无所知,也许有一个代码示例

祝你有美好的一天!

【问题讨论】:

    标签: php html css joomla less


    【解决方案1】:

    来自documentation of lessphp

    不过还是有问题。 checkedCompile 非常基础,它只检查输入文件的修改时间。它不知道来自@import 的任何文件。

    出于这个原因,我们还缓存了Compile。它稍微复杂一些,但让我们能够检查所有文件的更改,包括导入的文件。它接受一个参数,要么是我们要编译的文件的名称,要么是一个现有的缓存对象。它的返回值是一个更新的缓存对象。

    所以看来cachedCompile 是适合你的方法。

    这是您案例的代码:

    require_once(__DIR__ . '/less/lessc.inc.php');
    
    $inputFile  = __DIR__ . "/less/style.less";
    $outputFile = __DIR__ . "/css/style.css";
    $cacheFile  = $inputFile . ".cache";
    
    if (file_exists($cacheFile)) {
        $cache = unserialize(file_get_contents($cacheFile));
    } else {
        $cache = $inputFile;
    }
    
    $less = new lessc;
    $newCache = $less->cachedCompile($cache);
    
    if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
        file_put_contents($cacheFile, serialize($newCache));
        file_put_contents($outputFile, $newCache['compiled']);
    }
    

    【讨论】:

    • 兄弟...这是我得到的最棒的支持!非常感谢你这篇非常有用的帖子!
    猜你喜欢
    • 1970-01-01
    • 2017-08-05
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    相关资源
    最近更新 更多