Created
January 29, 2023 10:04
-
-
Save shibbirweb/5711872a57b2afaf7251a8faf40f137b to your computer and use it in GitHub Desktop.
Laravel vite unique hot path
This file contains 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 | |
// add custom global helper function here | |
use Illuminate\Support\Facades\Vite as ViteFacade; | |
if (!function_exists('module_vite_assets_unique_hot_path')) { | |
/** | |
* Support for vite assets with unique hot path | |
* | |
* @param array $assets | |
* @param string|null $module | |
* @param string|null $path | |
* @return \Illuminate\Foundation\Vite | |
*/ | |
function module_vite_assets_unique_hot_path(array $assets, ?string $module = null, ?string $path = null): \Illuminate\Foundation\Vite | |
{ | |
// build-vitetest | |
$hot_path = $module ? "vite-$module.hot" : 'vite.hot'; | |
$hot_file = $path ?? storage_path($hot_path); // example: vite-build-theme.hot | |
return ViteFacade::useHotFile($hot_file) | |
->useBuildDirectory($module ?? 'build') | |
->useManifestFilename('manifest.json') | |
->withEntryPoints($assets); | |
} | |
} | |
if (!function_exists('module_vite_react_refresh')) { | |
/** | |
* Support for vite react HRM with unique hot path | |
* | |
* @param string|null $module | |
* @param string|null $path | |
* @return \Illuminate\Support\HtmlString | void | |
*/ | |
function module_vite_react_refresh(?string $module = null, ?string $path = null) | |
{ | |
$hot_path = $module ? "vite-$module.hot" : 'vite.hot'; | |
$hot_file = $path ?? storage_path($hot_path); // example: vite-build-theme.hot | |
return ViteFacade::useHotFile($hot_file) | |
->reactRefresh(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment