Skip to content

Commit ef72724

Browse files
committed
Added options to use custom CSS/JS minifiers
1 parent 7a4e1d0 commit ef72724

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

API.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,28 @@ The closure will receive five parameters:
181181
* Visibility: **protected**
182182

183183

184+
### $css_minifier
185+
186+
protected \Closure $css_minifier
187+
188+
Closure used by the pipeline to minify CSS assets.
189+
190+
191+
192+
* Visibility: **protected**
193+
194+
195+
### $js_minifier
196+
197+
protected \Closure $js_minifier
198+
199+
Closure used by the pipeline to minify JavaScript assets.
200+
201+
202+
203+
* Visibility: **protected**
204+
205+
184206
### $collections
185207

186208
protected array $collections = array()

src/Manager.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ class Manager
131131
*/
132132
protected $notify_command;
133133

134+
/**
135+
* Closure used by the pipeline to minify CSS assets.
136+
*
137+
* @var Closure
138+
*/
139+
protected $css_minifier;
140+
141+
/**
142+
* Closure used by the pipeline to minify JavaScript assets.
143+
*
144+
* @var Closure
145+
*/
146+
protected $js_minifier;
147+
134148
/**
135149
* Available collections.
136150
* Each collection is an array of assets.
@@ -191,8 +205,8 @@ public function config(array $config)
191205
if(isset($config[$option]))
192206
$this->$option = $config[$option];
193207

194-
// Set pipeline commands
195-
foreach(array('fetch_command', 'notify_command') as $option)
208+
// Set pipeline options
209+
foreach(array('fetch_command', 'notify_command', 'css_minifier', 'js_minifier') as $option)
196210
if(isset($config[$option]) and ($config[$option] instanceof Closure))
197211
$this->$option = $config[$option];
198212

@@ -429,10 +443,13 @@ public function resetJs()
429443
*/
430444
protected function cssPipeline()
431445
{
432-
return $this->pipeline($this->css, '.css', $this->css_dir, function ($buffer) {
446+
// If a custom minifier has been set use it, otherwise fallback to default
447+
$minifier = (isset($this->css_minifier)) ? $this->css_minifier : function ($buffer) {
433448
$min = new \CSSmin();
434449
return $min->run($buffer);
435-
});
450+
};
451+
452+
return $this->pipeline($this->css, '.css', $this->css_dir, $minifier);
436453
}
437454

438455
/**
@@ -442,9 +459,12 @@ protected function cssPipeline()
442459
*/
443460
protected function jsPipeline()
444461
{
445-
return $this->pipeline($this->js, '.js', $this->js_dir, function ($buffer) {
462+
// If a custom minifier has been set use it, otherwise fallback to default
463+
$minifier = (isset($this->js_minifier)) ? $this->js_minifier : function ($buffer) {
446464
return \JSMin::minify($buffer);
447-
});
465+
};
466+
467+
return $this->pipeline($this->js, '.js', $this->js_dir, $minifier);
448468
}
449469

450470
/**

0 commit comments

Comments
 (0)