我想将多个.scss文件编译为一个.css文件。
我的代码:
<?php
class SassCompile {
private $scssFileType = ".scss";
private $cssFileType = ".css";
private $cssFileName = "style";
public $scssFolder = "scss/";
public $cssFolder = "css/";
public $scssPhp = "scssphp/scss.inc.php";
public $scssPhpCompression = "scss_formatter_compressed";
public function compile($scss_folder, $css_folder, $scssphp, $scss_format) {
require $scssphp;
$scss_compiler = new scssc();
$scss_compiler->setImportPaths($scss_folder);
$scss_compiler->setFormatter($scss_format);
$filelist = glob($scss_folder . "*" . $this->scssFileType);
foreach ($filelist as $file_path) {
$file_path_elements = pathinfo($file_path);
$file_name = $file_path_elements['filename'];
$file_content = file_get_contents($scss_folder . $file_name . $this->scssFileType);
$string_css = $scss_compiler->compile($file_content);
file_put_contents($css_folder . $this->cssFileName . $this->cssFileType, $string_css);
}
}
}
$sassCompile = new SassCompile();
$sassCompile->compile($sassCompile->scssFolder, $sassCompile->cssFolder, $sassCompile->scssPhp, $sassCompile->scssPhpCompression);
我的import.scss看起来像
@import "style";
@import "test";
我的scss文件夹中有两个文件:“_ style.scss”和“_test.scss”。 这些文件将编译到我在css文件夹中的stle.css。
每次重新加载页面时,都会编译css。当我有更多用户时,它会杀死我的网络服务器。
如果自最新编译完成以来文件有变化,我如何添加一个仅编译的函数?
谢谢