Skip to content

Instantly share code, notes, and snippets.

@shibbirweb
Created January 29, 2023 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shibbirweb/5711872a57b2afaf7251a8faf40f137b to your computer and use it in GitHub Desktop.
Save shibbirweb/5711872a57b2afaf7251a8faf40f137b to your computer and use it in GitHub Desktop.
Laravel vite unique hot path
<?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