Last active
January 27, 2023 20:50
-
-
Save dmason30/01a31f1ec7b8e68285d0b54e64b9f022 to your computer and use it in GitHub Desktop.
Laravel Nova combine tools command
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
<!DOCTYPE html> | |
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" dir="{{ \Laravel\Nova\Nova::rtlEnabled() ? 'rtl' : 'ltr' }}" class="h-full font-sans antialiased"> | |
<head> | |
<meta name="theme-color" content="#fff"> | |
<meta charset="utf-8"> | |
<meta name="csrf-token" content="{{ csrf_token() }}"> | |
<meta name="viewport" content="width=device-width"/> | |
<meta name="locale" content="{{ str_replace('_', '-', app()->getLocale()) }}"/> | |
@include('nova::partials.meta') | |
<!-- Styles --> | |
<link rel="stylesheet" href="{{ mix('app.css', 'vendor/nova') }}"> | |
<!-- Tool Styles --> | |
<link rel="stylesheet" href="{{asset('vendor/nova-tools/app.css')}}"> | |
<script> | |
if (localStorage.novaTheme === 'dark' || (!('novaTheme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { | |
document.documentElement.classList.add('dark') | |
} else { | |
document.documentElement.classList.remove('dark') | |
} | |
</script> | |
</head> | |
<body class="min-w-site text-sm font-medium min-h-full text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-gray-900 overscroll-none"> | |
@inertia | |
<div class="relative z-50"> | |
<div id="notifications" name="notifications"></div> | |
</div> | |
<div> | |
<div id="dropdowns" name="dropdowns"></div> | |
<div id="modals" name="modals"></div> | |
</div> | |
<!-- Scripts --> | |
<script src="{{ mix('manifest.js', 'vendor/nova') }}"></script> | |
<script src="{{ mix('vendor.js', 'vendor/nova') }}"></script> | |
<script src="{{ mix('app.js', 'vendor/nova') }}"></script> | |
<!-- Build Nova Instance --> | |
<script> | |
const config = @json(\Laravel\Nova\Nova::jsonVariables(request())); | |
window.Nova = createNovaApp(config) | |
Nova.countdown() | |
</script> | |
<!-- Tool Scripts --> | |
<script src="{{ asset('/vendor/nova-tools/app.js') }}"></script> | |
<!-- Start Nova --> | |
<script defer> | |
Nova.liftOff() | |
</script> | |
</body> | |
</html> |
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 | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
use Illuminate\Http\Request; | |
use Laravel\Nova\Asset; | |
use Laravel\Nova\Events\ServingNova; | |
use Laravel\Nova\Nova; | |
class PublishNovaToolsCommand extends Command | |
{ | |
protected $signature = 'nova:tools:publish'; | |
protected $description = 'Combines nova styles and scripts into single asset files'; | |
public function handle() | |
{ | |
ServingNova::dispatch(new Request()); | |
foreach (['allScripts' => 'js', 'allStyles' => 'css'] as $method => $type) { | |
$content = ''; | |
/** @var Asset $file */ | |
foreach (Nova::{$method}() as $file) { | |
$name = $file->name(); | |
$path = $file->isRemote() ? public_path($file->path()) : $file->path(); | |
$this->components->task("Reading asset [$name] from [$path]", function () use (&$content, $path) { | |
$result = file_get_contents($path); | |
if ($result) { | |
$content .= $result; | |
} | |
return file_exists($path); | |
}); | |
} | |
if ($content) { | |
$path = public_path('/vendor/nova-tools/app.'.$type); | |
$this->components->task("Writing file [$path]", fn () => file_put_contents($path, $content)); | |
$this->line(''); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment