Appearance
Tag generation
Overview
When you use the @vite and @tag directives, Laravel Vite outputs the HTML needed to load your entrypoints: a <script type="module"> tag for every script and a <link rel="stylesheet"> tag for every style.
In development, these tags point to the Vite development server. In production, they point to the files listed in the manifest, which are resolved as explained in server and manifest modes. The base path of the generated URLs follows the ASSET_URL environment variable, as described in building for production.
The default output is enough for most applications. When you need something different, for instance to add attributes such as crossorigin or defer, you can change how tags are generated.
Override via callbacks
The simplest way to customize the tags is to register callbacks with Vite::makeScriptTagsUsing and Vite::makeStyleTagsUsing. The first one is used for script tags, the second one for style tags. They are typically registered in the boot method of a service provider, so they apply to every request.
With them, you decide what markup is generated for each included asset, while the rest of the behavior (development server detection, manifest resolution) stays untouched.
Upgrading from 0.1.x
These two methods replace Vite::generateTagsUsing, which no longer exists. See the upgrade guide.
Subresource Integrity
Subresource Integrity lets the browser verify that a file served from another origin, such as a CDN, has not been tampered with. It requires an integrity attribute containing a hash of the file and, for cross-origin requests, a crossorigin attribute.
Since these are plain attributes on the generated tags, they can be added with the callbacks described above. The hash must be computed from the built files, so this only makes sense for the production build: in development, files are served by the Vite server and change constantly.
Override the implementation
If callbacks are not enough, the whole tag generation logic can be replaced. It is defined by the tag_generator interface, which can be set in the interfaces section of config/vite.php.
Point it to your own class implementing the same interface, and Laravel Vite will use it to generate every script and link tag.