Skip to content

Commit 8d305ca

Browse files
authored
Merge pull request #4522 from Kovah/v5-vite-assets
Extend config to support custom Vite styles and scripts
2 parents d388329 + 01aaec9 commit 8d305ca

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/config/backpack/base.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@
7474
// 'css/app.css' => '',
7575
],
7676

77+
// CSS files that are loaded in all pages, using Laravel's @vite() helper
78+
// Please note that support for Vite was added in Laravel 9.19. Earlier versions are not able to use this feature.
79+
'vite_styles' => [ // resource file_path
80+
// 'resources/css/app.css' => '',
81+
],
82+
7783
// ------
7884
// HEADER
7985
// ------
@@ -146,10 +152,15 @@
146152
],
147153

148154
// JS files that are loaded in all pages, using Laravel's mix() helper
149-
'mix_scripts' => [// file_path => manifest_directory_path
155+
'mix_scripts' => [ // file_path => manifest_directory_path
150156
// 'js/app.js' => '',
151157
],
152158

159+
// JS files that are loaded in all pages, using Laravel's @vite() helper
160+
'vite_scripts' => [ // resource file_path
161+
// 'resources/js/app.js',
162+
],
163+
153164
// -------------
154165
// CACHE-BUSTING
155166
// -------------

src/resources/views/base/inc/head.blade.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@yield('before_styles')
1010
@stack('before_styles')
11-
11+
1212
@if (config('backpack.base.styles') && count(config('backpack.base.styles')))
1313
@foreach (config('backpack.base.styles') as $path)
1414
<link rel="stylesheet" type="text/css" href="{{ asset($path).'?v='.config('backpack.base.cachebusting_string') }}">
@@ -21,6 +21,10 @@
2121
@endforeach
2222
@endif
2323

24+
@if (config('backpack.base.vite_styles') && count(config('backpack.base.vite_styles')))
25+
@vite(config('backpack.base.vite_styles'))
26+
@endif
27+
2428
@yield('after_styles')
2529
@stack('after_styles')
2630

@@ -29,4 +33,4 @@
2933
<!--[if lt IE 9]>
3034
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
3135
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
32-
<![endif]-->
36+
<![endif]-->

src/resources/views/base/inc/scripts.blade.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
@endforeach
1111
@endif
1212

13+
@if (config('backpack.base.vite_scripts') && count(config('backpack.base.vite_scripts')))
14+
@vite(config('backpack.base.vite_scripts'))
15+
@endif
16+
1317
@include('backpack::inc.alerts')
1418

1519
{{-- page script --}}
@@ -66,4 +70,4 @@
6670

6771
@if(config('app.debug'))
6872
@include('crud::inc.ajax_error_frame')
69-
@endif
73+
@endif

0 commit comments

Comments
 (0)