Fix #1727 Recompile SCSS/LESS files when imported file is changed

- import된 파일 목록을 따로 보관해 두었다가, 그 중 하나라도 변경되었다면 다시 컴파일
- PHP의 stat cache 덕분에 성능 영향은 크지 않을 것으로 보이나, 모니터링 필요
This commit is contained in:
Kijin Sung 2021-06-20 22:02:26 +09:00
parent f416b7c8a4
commit 664a68fc2a
2 changed files with 57 additions and 7 deletions

View file

@ -298,11 +298,47 @@ class FrontEndFileHandler extends Handler
$compiledFileName = $file->fileName . ($minify ? '.min' : '') . '.css';
$compiledFileHash = sha1($file->fileRealPath . ':' . serialize($file->vars));
$compiledFilePath = \RX_BASEDIR . self::$assetdir . '/compiled/' . $compiledFileHash . '.' . $compiledFileName;
$importedFileName = $file->fileName . ($minify ? '.min' : '') . '.imports.php';
$importedFilePath = \RX_BASEDIR . self::$assetdir . '/compiled/' . $compiledFileHash . '.' . $importedFileName;
if (!file_exists($compiledFilePath) || filemtime($compiledFilePath) < filemtime($file->fileFullPath))
if (!file_exists($compiledFilePath))
{
$recompile = 1;
}
else
{
$compiledTime = filemtime($compiledFilePath);
if ($compiledTime < filemtime($file->fileFullPath))
{
$recompile = 2;
}
else
{
$checklist = Rhymix\Framework\Storage::readPHPData($importedFilePath);
if (is_array($checklist))
{
$recompile = 0;
foreach ($checklist as $filename)
{
if (!file_exists($filename) || filemtime($filename) > $compiledTime)
{
$recompile = 3;
break;
}
}
}
else
{
$recompile = 4;
}
}
}
if ($recompile)
{
$method_name = 'compile' . $file->fileExtension;
$success = Rhymix\Framework\Formatter::$method_name($file->fileFullPath, $compiledFilePath, $file->vars, $minify);
Rhymix\Framework\Formatter::$method_name($file->fileFullPath, $compiledFilePath, $file->vars, $minify);
}
$file->fileName = $compiledFileHash . '.' . $compiledFileName;