Skip to content

Commit

Permalink
Add asset ID from mix
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Feb 14, 2021
1 parent 520c4db commit 831fb02
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 8 additions & 2 deletions resources/views/components/layouts/base.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
@livewireStyles
<link rel="preconnect" href="https://fonts.gstatic.com">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Commissioner:wght@200;300;400;500;600;700&amp;family=JetBrains+Mono:ital@0;1&amp;display=swap">
<link rel="stylesheet" href="{{ route('filament.asset', ['path' => 'css/filament.css']) }}" />
<link rel="stylesheet" href="{{ route('filament.asset', [
'id' => Filament\get_asset_id('/css/filament.css'),
'path' => 'css/filament.css',
]) }}" />
@stack('filament-styles')
</head>

Expand All @@ -20,7 +23,10 @@
<x-filament::notification />

@livewireScripts
<script src="{{ route('filament.asset', ['path' => 'js/filament.js']) }}"></script>
<script src="{{ route('filament.asset', [
'id' => Filament\get_asset_id('/js/filament.js'),
'path' => 'js/filament.js',
]) }}"></script>
@stack('filament-scripts')
</body>
</html>
22 changes: 22 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Filament;

use Illuminate\Support\Str;
use League\Glide\Urls\UrlBuilderFactory;

if (! function_exists('Filament\format_attributes')) {
Expand All @@ -27,6 +28,27 @@ function format_bytes($size, $precision = 0)
}
}

if (! function_exists('Filament\get_asset_id')) {
function get_asset_id($path)
{
$manifestPath = __DIR__.'/../dist/mix-manifest.json';

if(! file_exists($manifestPath)) return null;

$manifest = json_decode(file_get_contents($manifestPath), true);

if (! array_key_exists($path, $manifest)) return null;

$path = $manifest[$path];

if (! str_contains($path, 'id=')) return null;

$id = (string) Str::of($path)->after('id=');

return $id;
}
}

if (! function_exists('Filament\get_image_url')) {
function get_image_url($path, $manipulations = [])
{
Expand Down

0 comments on commit 831fb02

Please sign in to comment.