Skip to content

Commit b9b5c5c

Browse files
authored
make Vite macroable (#44198)
1 parent 92bd07b commit b9b5c5c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Illuminate/Foundation/Vite.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
use Illuminate\Support\Collection;
88
use Illuminate\Support\HtmlString;
99
use Illuminate\Support\Str;
10+
use Illuminate\Support\Traits\Macroable;
1011

1112
class Vite implements Htmlable
1213
{
14+
use Macroable;
15+
1316
/**
1417
* The Content Security Policy nonce to apply to all generated tags.
1518
*

tests/Foundation/FoundationViteTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,25 @@ public function testViteCanOverrideHotFilePath()
614614
$this->cleanViteHotFile('cold');
615615
}
616616

617+
public function testViteIsMacroable()
618+
{
619+
$this->makeViteManifest([
620+
'resources/images/profile.png' => [
621+
'src' => 'resources/images/profile.png',
622+
'file' => 'assets/profile.versioned.png',
623+
],
624+
], $buildDir = Str::random());
625+
Vite::macro('image', function ($asset, $buildDir = null) {
626+
return $this->asset("resources/images/{$asset}", $buildDir);
627+
});
628+
629+
$path = ViteFacade::image('profile.png', $buildDir);
630+
631+
$this->assertSame("https://example.com/{$buildDir}/assets/profile.versioned.png", $path);
632+
633+
$this->cleanViteManifest($buildDir);
634+
}
635+
617636
protected function makeViteManifest($contents = null, $path = 'build')
618637
{
619638
app()->singleton('path.public', fn () => __DIR__);

0 commit comments

Comments
 (0)