Last active
April 2, 2016 14:20
-
-
Save shoman4eg/0cb7ce3cc382b6d7b849 to your computer and use it in GitHub Desktop.
Minifier.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'JSmin.php'; | |
include 'CSSmin.php'; | |
$sTemplatePath = $_SERVER['DOCUMENT_ROOT'] . 'Путь к шаблону'; | |
function minify(array $arr) { | |
foreach ($arr as $orig => $minVersion) { | |
$pathInfo = pathinfo($orig); | |
if (file_exists($minVersion)) { | |
$pathInfoMin = pathinfo($minVersion); | |
} | |
if (filemtime($orig) > filemtime($minVersion)) { | |
switch ($pathInfo['extension']) { | |
case 'css': | |
$filters = array ( | |
"ImportImports" => false, | |
"RemoveComments" => true, | |
"RemoveEmptyRulesets" => false, | |
"RemoveEmptyAtBlocks" => false, | |
"ConvertLevel3AtKeyframes" => false, | |
"ConvertLevel3Properties" => false, | |
"Variables" => true, | |
"RemoveLastDelarationSemiColon" => false, | |
); | |
$plugins = array ( | |
"Variables" => true, | |
"ConvertFontWeight" => false, | |
"ConvertHslColors" => false, | |
"ConvertRgbColors" => false, | |
"ConvertNamedColors" => false, | |
"CompressColorValues" => true, | |
"CompressUnitValues" => true, | |
"CompressExpressionValues" => false | |
); | |
$minCode = CssMin::minify(file_get_contents($orig), array(), $plugins); | |
break; | |
case 'js': | |
$minCode = JsMin::minify(file_get_contents($orig)); | |
break; | |
} | |
file_put_contents($minVersion, $minCode, LOCK_EX); | |
if (file_exists($minVersion)) { | |
$pathInfoMin = pathinfo($minVersion); | |
} | |
echo $pathInfoMin['basename']. " Сгенерирован" . "\n"; | |
} else { | |
echo sprintf('%s Актуальная версия %s', $pathInfoMin['basename'], $pathInfo['basename']) . "\n"; | |
} | |
} | |
} | |
$js = array( | |
$sTemplatePath . "js/sidebarmenu.js" => $sTemplatePath . "js/sidebarmenu.min.js", | |
$_SERVER['DOCUMENT_ROOT'] . '/bitrix/cache/js/ru/slid_main/kernel_main/kernel_main.js' => $_SERVER['DOCUMENT_ROOT'] . '/bitrix/cache/js/ru/slid_main/kernel_main/kernel_main.min.js', | |
$sTemplatePath . "js/utils.js" => $sTemplatePath . "js/utils.min.js", | |
$sTemplatePath . "js/classifieds.js" => $sTemplatePath . "js/classifieds.min.js", | |
); | |
$css = array( | |
$sTemplatePath . "css/bootstrap.css" => $sTemplatePath . "css/bootstrap.min.css", | |
$sTemplatePath . "css/classifieds.css" => $sTemplatePath . "css/classifieds.min.css", | |
$sTemplatePath . "css/forum.css" => $sTemplatePath . "css/forum.min.css", | |
); | |
minify($js); | |
minify($css); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment