Created
July 11, 2025 08:33
-
-
Save dave-mills/1707a00e242638af20c71489991a28e1 to your computer and use it in GitHub Desktop.
Laravel Valet Driver for serving Vite Apps locally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Valet\Drivers\Custom; | |
use Valet\Drivers\ValetDriver; | |
class VueValetDriver extends ValetDriver | |
{ | |
/** | |
* Determine if the driver serves the request. | |
*/ | |
public function serves(string $sitePath, string $siteName, string $uri): bool | |
{ | |
if ((file_exists($sitePath.'/vite.config.js') || file_exists($sitePath . '/vite.config.ts')) && file_exists($sitePath.'/package.json') && file_exists($sitePath.'/index.html')) { | |
return true; | |
} | |
return false; | |
} | |
/** | |
* Determine if the incoming request is for a static file. | |
*/ | |
public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */ | |
{ | |
if (file_exists($staticFilePath = $sitePath.'/dist/'.$uri)) { | |
return $staticFilePath; | |
} | |
return false; | |
} | |
/** | |
* Get the fully resolved path to the application's front controller. | |
*/ | |
public function frontControllerPath(string $sitePath, string $siteName, string $uri): string | |
{ | |
return $sitePath.'/dist/index.html'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment