JavaScript: Load minified library assets if available
This commit is contained in:
parent
5c5e83a700
commit
64d1574972
|
@ -3,6 +3,7 @@
|
|||
|
||||
namespace Icinga\Application\Libraries;
|
||||
|
||||
use CallbackFilterIterator;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\Json\JsonDecodeException;
|
||||
use Icinga\Util\Json;
|
||||
|
@ -202,10 +203,20 @@ class Library
|
|||
|
||||
$this->{$type . 'AssetPath'} = $dir;
|
||||
|
||||
return new RecursiveIteratorIterator(new RecursiveDirectoryIterator(
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(
|
||||
$dir,
|
||||
RecursiveDirectoryIterator::CURRENT_AS_PATHNAME | RecursiveDirectoryIterator::SKIP_DOTS
|
||||
));
|
||||
if ($type === 'static') {
|
||||
return $iterator;
|
||||
}
|
||||
|
||||
return new CallbackFilterIterator(
|
||||
$iterator,
|
||||
function ($path) use ($type) {
|
||||
return substr($path, -5 - strlen($type)) !== ".min.$type";
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
$this->assets = [];
|
||||
|
|
|
@ -157,12 +157,24 @@ class JavaScript
|
|||
// Library files need to be namespaced first before they can be included
|
||||
foreach (Icinga::app()->getLibraries() as $library) {
|
||||
foreach ($library->getJsAssets() as $file) {
|
||||
$js .= self::optimizeDefine(
|
||||
$alreadyMinified = false;
|
||||
if ($minified && file_exists(($minFile = substr($file, 0, -3) . '.min.js'))) {
|
||||
$alreadyMinified = true;
|
||||
$file = $minFile;
|
||||
}
|
||||
|
||||
$content = self::optimizeDefine(
|
||||
file_get_contents($file),
|
||||
$file,
|
||||
$library->getJsAssetPath(),
|
||||
$library->getName()
|
||||
) . "\n\n\n";
|
||||
);
|
||||
|
||||
if ($alreadyMinified) {
|
||||
$out .= ';' . ltrim(trim($content), ';') . "\n";
|
||||
} else {
|
||||
$js .= $content . "\n\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue