Download the PHP package lukaskleinschmidt/kirby-laravel-vite without Composer
On this page you can find all versions of the php package lukaskleinschmidt/kirby-laravel-vite. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lukaskleinschmidt/kirby-laravel-vite
More information about lukaskleinschmidt/kirby-laravel-vite
Files in lukaskleinschmidt/kirby-laravel-vite
Package kirby-laravel-vite
Short Description Kirby Laravel Vite
License MIT
Informations about the package kirby-laravel-vite
Kirby Laravel Vite
After installation, you can use the vite()
helper to include Vite assets in your Kirby project.
This plugin works best with the laravel-vite-plugin.
Note
Some features are not properly documented yet. Feel free to skim through the source code if you think something is missing.
Installation
Composer
Git Submodule
Download
Download and copy this repository to /site/plugins/laravel-vite
.
Installing The Laravel Vite Plugin
Documentation for the Laravel Vite plugin can be found on the Laravel website.
Refreshing On Save
When your application is built using traditional server-side rendering, Vite can improve your development workflow by automatically refreshing the browser when you make changes to template or snippet files in your application. To get started, you can simply specify the refresh option.
Autoloading Template Specific Assets
If you used the @auto
option for your assets, you can do the same with optional assets.
Optional Assets
When you use the Kirby Query Language
or prepend an @
to an asset, those assets are treated as optional.
Meaning the plugin will only include assets that actually exist at the given source path.
Note
Remember to include the optional assets in vite as well so that they are actually available once bundled. Assets not included in vite will work in development mode but not when bundled.
Custom Panel Scripts And Styles
Note Available since 1.1.0
You can use vite for your panel.css
or panel.js
too. Since the plugin requires the Kirby instance to work you need to define the assets in the ready callback to be able to use the vite()
helper.
Note
Remember to include the optional panel assets in vite as well so that they are actually available once bundled. Assets not included in vite will work in development mode but not when bundled.
React
If you build your front-end using the React framework you will also need to call the additional vite()->reactRefresh()
method alongside your existing vite()
call.
The vite()->reactRefresh()
method must be called before the vite()
call.
Processing Static Assets With Vite
When referencing assets in your JavaScript or CSS, Vite automatically processes and versions them. In addition, when your application is built using traditional server-side rendering, Vite can also process and version static assets that you reference in your templates.
However, in order to accomplish this, you need to make Vite aware of your assets by importing the static assets into the application's entry point.
For example, if you want to process and version all images stored in assets/images
and all fonts stored in assets/fonts
, you should add the following in your application's assets/js/app.js
entry point:
These assets will now be processed by Vite when running npm run build
. You can then reference these assets in your templates using the vite()->asset()
method, which will return the versioned URL for a given asset:
Arbitrary Attributes
If you need to include additional attributes on your script and style tags, such as the data-turbo-track
attribute, you may specify them via the plugin options.
If you need to conditionally add attributes, you may pass a callback that will receive the asset source path, its URL, its manifest chunk, and the entire manifest:
Note
The$chunk
and$manifest
arguments will be empty while the Vite development server is running.
Advanced Customization
Out of the box, Laravel's Vite plugin uses sensible conventions that should work for the majority of applications. However, sometimes you may need to customize Vite's behavior. To enable additional customization options, you can use the following options:
Note If you need access to the Kirby instance, you can use a callback function to define the option. Alternatively, you can configure Vite in Kirby's ready callback or directly in the template.
Within the vite.config.js
file, you should then specify the same configuration:
Commercial Usage
This plugin is free if charge, but please consider a donation if you use it in a commercial project.
License
MIT
Credits
A good portion of the documentation has been copied from the Laravel website and adapted to the Kirby implementation.