@php
    $manifestPath = public_path('build/manifest.json');
@endphp

@if (file_exists($manifestPath))
    @vite(['resources/js/app.js'])
@else
    @php
        $jsFiles = glob(public_path('build/assets/app-*.js')) ?: [];
        usort($jsFiles, fn ($a, $b) => filemtime($b) <=> filemtime($a));
        $js = $jsFiles[0] ?? null;
    @endphp

    @if ($js)
        <script type="module" src="{{ str_replace(public_path(), '', $js) }}"></script>
    @endif
@endif
