Skip to content

Commit

Permalink
Fix invalid hot file #490
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine committed Aug 22, 2023
1 parent 55de906 commit ee9a6b0
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 25 deletions.
7 changes: 5 additions & 2 deletions demo/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Providers;

use App\Support\Vite;
use Code16\Sharp\SharpServiceProvider;
use Code16\Sharp\View\Components\Vite as SharpViteComponent;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
Expand All @@ -12,7 +12,10 @@ public function register()
{
$this->app->register(SharpServiceProvider::class);
// $this->app->bind(SharpUploadModel::class, Media::class)
$this->app->singleton(\Illuminate\Foundation\Vite::class, Vite::class);

$this->app->bind(SharpViteComponent::class, function () {
return new SharpViteComponent(hotFile: base_path('../resources/assets/dist/hot'));
});
}

public function boot()
Expand Down
17 changes: 0 additions & 17 deletions demo/app/Support/Vite.php

This file was deleted.

1 change: 1 addition & 0 deletions demo/config/sharp.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
'resources/css/sharp-extension.css',
],
],
'activate_custom_fields' => true,
],

'markdown_editor' => [
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

@vite('resources/js/sharp-plugin.js')
1 change: 1 addition & 0 deletions demo/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel([
'resources/js/sharp-plugin.js',
'resources/css/sharp-extension.css',
]),
],
Expand Down
19 changes: 13 additions & 6 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,30 @@
{{ $title ?? null }}
</x-sharp::title>

@vite([
'resources/assets/sass/vendors.scss',
'resources/assets/sass/app.scss'
], '/vendor/sharp')
<x-sharp::vite>
@vite([
'resources/assets/sass/vendors.scss',
'resources/assets/sass/app.scss'
], '/vendor/sharp')
</x-sharp::vite>

<x-sharp::root-styles />

<x-sharp::extensions.injected-assets />

@include('sharp::partials.head')

@vite('resources/assets/js/client-api.js', '/vendor/sharp')
<x-sharp::vite>
@vite('resources/assets/js/client-api.js', '/vendor/sharp')
</x-sharp::vite>

<x-sharp::extensions.custom-fields-script />

<script defer src="/vendor/sharp/lang.js?version={{ sharp_version() }}&locale={{ app()->getLocale() }}"></script>
@vite('resources/assets/js/sharp.js', '/vendor/sharp')

<x-sharp::vite>
@vite('resources/assets/js/sharp.js', '/vendor/sharp')
</x-sharp::vite>
</head>
<body {{ $attributes }}>
<x-sharp::alert.assets-outdated />
Expand Down
24 changes: 24 additions & 0 deletions src/View/Components/Vite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Code16\Sharp\View\Components;


use Illuminate\View\Component;

class Vite extends Component
{
public function __construct(?string $hotFile = null)
{
\Illuminate\Support\Facades\Vite::useHotFile($hotFile ?? public_path('vendor/sharp/hot'));
}

public function render(): string
{
return '{{ $slot }}{{ $append() }}';
}

public function append(): void
{
\Illuminate\Support\Facades\Vite::useHotFile(public_path('hot')); // reset to default hot file location
}
}

0 comments on commit ee9a6b0

Please sign in to comment.