Skip to content

Tag generation


By default, Laravel Vite generates basic script and style tags, with no specific attribute. However, you are free to override this behavior and use your own logic to generate the tags.

Override via callbacks

You may call Vite::makeScriptTagsUsing() and Vite::makeStyleTagsUsing() in your application service provider or a middleware.

// Overrides script tag generation
Vite::makeScriptTagsUsing(function (string $url, Chunk $chunk = null): string {
    return sprintf('<script type="module" src="%s" defer></script>', $url);

// Overrides style tag generation
Vite::makeStyleTagsUsing(function (string $url, Chunk $chunk = null): string {
    return sprintf('<link rel="stylesheet" href="%s" crossorigin="anonymous" />', $url);

Subresource Integrity

Subresource Integrity is supported through vite-plugin-manifest-sri. When this plugin is registered, Vite will add integrity and crossorigin attributes on entrypoint tags.

Script-imported CSS files are not supported

The extended manifest file from vite-plugin-manifest-sri does not add an integrity property to imported CSS.

If you need to ensure CSS integrity, register them as entrypoints instead.

Override the implementation

Alternatively, you may implement the Innocenzi\Vite\TagGenerators\TagGenerator interface.

The interfaces.tag_generator configuration option provides you with a convenient way of binding your custom implementation.

Tag generation has loaded