From 4762aee0341cb5b04772bb25a93bdf826048c7f3 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Tue, 25 Oct 2022 00:32:08 +1100 Subject: [PATCH] [1.x] Vite preloading (#196) * preloading * require latest laravel version --- composer.json | 2 +- src/Console/InstallsInertiaStacks.php | 4 +++- stubs/inertia-common/resources/views/app.blade.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 65dc442a5..3dcd002b3 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "illuminate/validation": "^9.21" }, "conflict": { - "laravel/framework": "<9.19.0" + "laravel/framework": "<9.37.0" }, "autoload": { "psr-4": { diff --git a/src/Console/InstallsInertiaStacks.php b/src/Console/InstallsInertiaStacks.php index 9130ddc36..20f3ce53e 100644 --- a/src/Console/InstallsInertiaStacks.php +++ b/src/Console/InstallsInertiaStacks.php @@ -42,6 +42,7 @@ protected function installInertiaVueStack() // Middleware... $this->installMiddlewareAfter('SubstituteBindings::class', '\App\Http\Middleware\HandleInertiaRequests::class'); + $this->installMiddlewareAfter('\App\Http\Middleware\HandleInertiaRequests::class', '\Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class'); copy(__DIR__.'/../../stubs/inertia-common/app/Http/Middleware/HandleInertiaRequests.php', app_path('Http/Middleware/HandleInertiaRequests.php')); @@ -153,12 +154,13 @@ protected function installInertiaReactStack() // Middleware... $this->installMiddlewareAfter('SubstituteBindings::class', '\App\Http\Middleware\HandleInertiaRequests::class'); + $this->installMiddlewareAfter('\App\Http\Middleware\HandleInertiaRequests::class', '\Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class'); copy(__DIR__.'/../../stubs/inertia-common/app/Http/Middleware/HandleInertiaRequests.php', app_path('Http/Middleware/HandleInertiaRequests.php')); // Views... copy(__DIR__.'/../../stubs/inertia-common/resources/views/app.blade.php', resource_path('views/app.blade.php')); - $this->replaceInFile("@vite('resources/js/app.js')", '@viteReactRefresh'.PHP_EOL." @vite('resources/js/app.jsx')", resource_path('views/app.blade.php')); + $this->replaceInFile("@vite(\"resources/js/Pages/{\$page['component']}.vue\")", '@viteReactRefresh'.PHP_EOL." @vite(\"resources/js/Pages/{\$page['component']}.jsx\")", resource_path('views/app.blade.php')); // Components + Pages... (new Filesystem)->ensureDirectoryExists(resource_path('js/Components')); diff --git a/stubs/inertia-common/resources/views/app.blade.php b/stubs/inertia-common/resources/views/app.blade.php index fe91e9729..b194a264a 100644 --- a/stubs/inertia-common/resources/views/app.blade.php +++ b/stubs/inertia-common/resources/views/app.blade.php @@ -11,7 +11,7 @@ @routes - @vite('resources/js/app.js') + @vite("resources/js/Pages/{$page['component']}.vue") @inertiaHead