goognet / vite-plain-html
Makes Laravel's Vite helper emit plain HTML link tags, without the XHTML style slash.
Requires
- php: ^8.3.0
- laravel/framework: ^13.0
Requires (Dev)
- laravel/pint: ^1.32.1
- orchestra/testbench: ^11.0
- pestphp/pest: ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Makes Laravel's Vite helper emit plain HTML link tags, without the XHTML style slash.
Laravel's @vite directive hardcodes the terminator on every link tag it prints:
<link rel="preload" as="style" href="/build/assets/app-abc123.css" /> <link rel="stylesheet" href="/build/assets/app-abc123.css" />
This package makes it print:
<link rel="preload" as="style" href="/build/assets/app-abc123.css"> <link rel="stylesheet" href="/build/assets/app-abc123.css">
Installation
composer require goognet/vite-plain-html
That is the whole setup. The service provider is auto-discovered, and your views keep calling @vite(...) as they do today.
Note this is a runtime dependency, not a dev one: the tags are generated on every request.
How it works
Illuminate\Foundation\Vite builds its link tags in three protected methods, each ending in a hardcoded ' />':
| method | tag |
|---|---|
makePreloadTagForChunk |
<link rel="preload"> |
makeStylesheetTagWithAttributes |
<link rel="stylesheet"> |
renderFontPreloads |
<link rel="preload" as="font">, from @vite fonts |
There is no option for it — useStyleTagAttributes() and usePreloadTagAttributes() only add attributes.
So this package subclasses the helper and rebinds it in the container. Each override hands the work to Laravel and rewrites the terminator on the way out, so none of Laravel's attribute logic is copied here and an upgrade cannot leave a stale copy of it behind:
protected function makeStylesheetTagWithAttributes($url, $attributes) { return PlainHtml::tags(parent::makeStylesheetTagWithAttributes($url, $attributes)); }
The terminator is only rewritten at the end of a line, so a /> inside an attribute value is left alone.
Script tags are untouched — Laravel already prints those as <script ...></script>.
Requirements
- PHP 8.3+
- Laravel 13
Laravel 12 and earlier have the same two link tag methods but no renderFontPreloads, so this package targets 13 only.
License
MIT. See LICENSE.md.