Skip to content

Commit

Permalink
Proxy: If DefaultJsMinifier exist use it for minify.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek authored Jan 6, 2021
1 parent 63377e5 commit e2bec23
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Proxy/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Baraja\Cms\Proxy;


use Baraja\AssetsLoader\Minifier\DefaultJsMinifier;
use Baraja\Plugin\Plugin;
use Baraja\Plugin\PluginManager;

Expand Down Expand Up @@ -53,8 +54,13 @@ public function run(string $path): void

$return .= ' * MD5 content hash: ' . md5($content = $this->renderContent($plugin)) . "\n";
$return .= ' */' . "\n\n\n";
$return .= $content;

echo $return . $content;
if (\class_exists(DefaultJsMinifier::class)) {
$return = (new DefaultJsMinifier)->minify($return);
}

echo $return;
die;
}

Expand All @@ -65,16 +71,13 @@ public function run(string $path): void
private function renderContent(Plugin $plugin): string
{
$return = '';

foreach ($this->pluginManager->getComponents($plugin, null) as $component) {
$return .= '/* Component ' . $component->getKey() . ' */' . "\n";
if (\is_file($component->getSource()) === true) {
$content = trim((string) file_get_contents($component->getSource()));

if (substr($content, -2) === '})') {
$content .= ';';
}

$return .= $content . "\n\n\n";
}
}
Expand Down

0 comments on commit e2bec23

Please sign in to comment.