bohnmedia / contao-vite-bundle
Integrates pentatrion/vite-bundle into Contao 5 and exposes Vite entry tags and asset URLs via both Twig functions and insert tags.
Package info
github.com/bohnmedia/contao-vite-bundle
Type:contao-bundle
pkg:composer/bohnmedia/contao-vite-bundle
Requires
- php: ^8.2
- contao/core-bundle: ^5.0
- contao/manager-plugin: ^2.0
- pentatrion/vite-bundle: ^8.0
- symfony/http-kernel: ^6.4 || ^7.0
Requires (Dev)
README
A small Contao 5 wrapper around pentatrion/vite-bundle. It
registers PentatrionViteBundle in Contao Manager Edition so its Twig
functions work out of the box, and additionally exposes the most common
rendering helpers as Contao insert tags for use outside of templates.
Installation
composer require bohnmedia/contao-vite-bundle
By default the bundle expects Vite to output its build artifacts into
public/build/. Both parts of that path can be overridden through the
underlying pentatrion_vite configuration:
# config/config.yaml pentatrion_vite: public_directory: public # default: public build_directory: build # default: build
See the pentatrion/vite-bundle reference for all available configuration options.
Rendering entry tags
Render the link and script tags for a Vite entry.
Twig
{{ vite_entry_link_tags('app') }}
{{ vite_entry_script_tags('app') }}
Insert tag
{{vite_entry_link_tags::app}}
{{vite_entry_script_tags::app}}
The insert tags behave like the Twig functions they wrap: an unknown
entry resolves to an empty string by default, unless you enable
throw_on_missing_entry in the configuration.
Resolving individual asset URLs
A named asset package vite is registered automatically, so Vite-hashed
assets resolve via Symfony's asset() function or Contao's {{asset::}}
insert tag.
Twig
{{ asset('@/images/favicon.svg', 'vite') }}
Insert tag
{{asset::@/images/favicon.svg::vite}}
License
MIT.