Skip to content

Commit 7821edf

Browse files
committed
add minify options and made some major changes
1 parent 6339c44 commit 7821edf

File tree

4 files changed

+144
-7
lines changed

4 files changed

+144
-7
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"require": {
2828
"php": ">=7.4",
29-
"illuminate/support": "^7.16"
29+
"illuminate/support": "^7.16",
30+
"matthiasmullie/minify": "^1.3"
3031
}
3132
}

composer.lock

+113-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/InlineAssets.php

+28-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,40 @@
44

55
use Illuminate\Support\HtmlString;
66
use Statamic\Tags\Tags;
7+
use MatthiasMullie\Minify;
78

89
class InlineAssets extends Tags
910
{
10-
public function index()
11+
public function js(): HtmlString
1112
{
1213
$asset = public_path(
13-
$this->get(['src', 'path'])
14+
$this->params->get(['src', 'path'])
1415
);
1516

16-
return new HtmlString(file_get_contents($asset));
17+
$response = file_get_contents($asset);
18+
19+
if ($this->params->bool('minify')) {
20+
$minifier = new Minify\JS($asset);
21+
$response = $minifier->minify();
22+
}
23+
24+
return new HtmlString($response);
1725
}
26+
27+
public function css(): HtmlString
28+
{
29+
$asset = public_path(
30+
$this->params->get(['src', 'path'])
31+
);
32+
33+
$response = file_get_contents($asset);
34+
35+
if ($this->params->bool('minify')) {
36+
$minifier = new Minify\CSS($asset);
37+
$response = $minifier->minify();
38+
}
39+
40+
return new HtmlString($response);
41+
}
42+
1843
}

src/ServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ServiceProvider extends AddonServiceProvider
1010
InlineAssets::class,
1111
];
1212

13-
public function boot()
13+
public function boot(): void
1414
{
1515
parent::boot();
1616
}

0 commit comments

Comments
 (0)