mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-25 23:04:51 +02:00
JavaScript: Load minified library assets if available
This commit is contained in:
parent
5c5e83a700
commit
64d1574972
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Application\Libraries;
|
namespace Icinga\Application\Libraries;
|
||||||
|
|
||||||
|
use CallbackFilterIterator;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Exception\Json\JsonDecodeException;
|
use Icinga\Exception\Json\JsonDecodeException;
|
||||||
use Icinga\Util\Json;
|
use Icinga\Util\Json;
|
||||||
@ -202,10 +203,20 @@ class Library
|
|||||||
|
|
||||||
$this->{$type . 'AssetPath'} = $dir;
|
$this->{$type . 'AssetPath'} = $dir;
|
||||||
|
|
||||||
return new RecursiveIteratorIterator(new RecursiveDirectoryIterator(
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(
|
||||||
$dir,
|
$dir,
|
||||||
RecursiveDirectoryIterator::CURRENT_AS_PATHNAME | RecursiveDirectoryIterator::SKIP_DOTS
|
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 = [];
|
$this->assets = [];
|
||||||
|
@ -157,12 +157,24 @@ class JavaScript
|
|||||||
// Library files need to be namespaced first before they can be included
|
// Library files need to be namespaced first before they can be included
|
||||||
foreach (Icinga::app()->getLibraries() as $library) {
|
foreach (Icinga::app()->getLibraries() as $library) {
|
||||||
foreach ($library->getJsAssets() as $file) {
|
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_get_contents($file),
|
||||||
$file,
|
$file,
|
||||||
$library->getJsAssetPath(),
|
$library->getJsAssetPath(),
|
||||||
$library->getName()
|
$library->getName()
|
||||||
) . "\n\n\n";
|
);
|
||||||
|
|
||||||
|
if ($alreadyMinified) {
|
||||||
|
$out .= ';' . ltrim(trim($content), ';') . "\n";
|
||||||
|
} else {
|
||||||
|
$js .= $content . "\n\n\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user