File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -536,6 +536,26 @@ protected function manifestPath($buildDirectory)
536
536
return public_path ($ buildDirectory .'/manifest.json ' );
537
537
}
538
538
539
+ /**
540
+ * Get a unique hash representing the current manifest, or null if there is no manifest.
541
+ *
542
+ * @return string|null
543
+ */
544
+ public function manifestHash ($ buildDirectory = null )
545
+ {
546
+ $ buildDirectory ??= $ this ->buildDirectory ;
547
+
548
+ if ($ this ->isRunningHot ()) {
549
+ return null ;
550
+ }
551
+
552
+ if (! is_file ($ path = $ this ->manifestPath ($ buildDirectory ))) {
553
+ return null ;
554
+ }
555
+
556
+ return md5_file ($ path ) ?: null ;
557
+ }
558
+
539
559
/**
540
560
* Get the chunk for the given entry point / asset.
541
561
*
Original file line number Diff line number Diff line change 5
5
/**
6
6
* @method static string useCspNonce(?string $nonce = null)
7
7
* @method static string|null cspNonce()
8
+ * @method static string|null manifestHash(?string $buildDirectory = null)
8
9
* @method static string asset(string $asset, string|null $buildDirectory)
9
10
* @method static string hotFile()
10
11
* @method static \Illuminate\Foundation\Vite useBuildDirectory(string $path)
Original file line number Diff line number Diff line change @@ -535,6 +535,36 @@ public function testItThrowsWhenUnableToFindAssetChunkInBuildMode()
535
535
ViteFacade::asset ('resources/js/missing.js ' );
536
536
}
537
537
538
+ public function testItDoesNotReturnHashInDevMode ()
539
+ {
540
+ $ this ->makeViteHotFile ();
541
+
542
+ $ this ->assertNull (ViteFacade::manifestHash ());
543
+
544
+ $ this ->cleanViteHotFile ();
545
+ }
546
+
547
+ public function testItGetsHashInBuildMode ()
548
+ {
549
+ $ this ->makeViteManifest (['a.js ' => ['src ' => 'a.js ' ]]);
550
+
551
+ $ this ->assertSame ('98ca5a789544599b562c9978f3147a0f ' , ViteFacade::manifestHash ());
552
+
553
+ $ this ->cleanViteManifest ();
554
+ }
555
+
556
+ public function testItGetsDifferentHashesForDifferentManifestsInBuildMode ()
557
+ {
558
+ $ this ->makeViteManifest (['a.js ' => ['src ' => 'a.js ' ]]);
559
+ $ this ->makeViteManifest (['b.js ' => ['src ' => 'b.js ' ]], 'admin ' );
560
+
561
+ $ this ->assertSame ('98ca5a789544599b562c9978f3147a0f ' , ViteFacade::manifestHash ());
562
+ $ this ->assertSame ('928a60835978bae84e5381fbb08a38b2 ' , ViteFacade::manifestHash ('admin ' ));
563
+
564
+ $ this ->cleanViteManifest ();
565
+ $ this ->cleanViteManifest ('admin ' );
566
+ }
567
+
538
568
public function testViteCanSetEntryPointsWithFluentBuilder ()
539
569
{
540
570
$ this ->makeViteManifest ();
You can’t perform that action at this time.
0 commit comments