Download the PHP package userfrosting/vite-php-twig without Composer
On this page you can find all versions of the php package userfrosting/vite-php-twig. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download userfrosting/vite-php-twig
More information about userfrosting/vite-php-twig
Files in userfrosting/vite-php-twig
Package vite-php-twig
Short Description Vite function for Twig templates
License MIT
Homepage https://github.com/userfrosting/vite-php-twig
Informations about the package vite-php-twig
Vite Manifest Support for PHP & Twig
Vite Manifest function for PHP & Twig Templates. Allows Vite manifest integration in PHP & Twig Templates without Symfony. Optimized for PHP-DI style containers.
Inspired by kellerkinderDE/vite-encore-bundle & PHP-Vite.
Installation
Documentation & Usage
Using standalone
ViteManifest
implements\UserFrosting\ViteTwig\ViteManifestInterface
if you prefer to type-hint against interfaces, for use with dependency injection.
Using with Twig
Requires Twig 3 or newer
Vite writes an manifest.json
file that contains all of the files needed for each "entry". To reference entries in Twig, you need to add the ViteTwigExtension
extension to the Twig Environment. This accept a ViteManifest
, which itself accept the path to the manifest.json
,
Now, to render all of the script
and link
tags for a specific "entry" (e.g. entry1
), you can:
If you have multiple entry point scripts on the same page, you should pass them in a single call to avoid duplicates - for example:
Vite default port
By default, vite will use port 5173
. However, if the port is already being used, Vite will automatically try the next available port so this may not be the actual port the server ends up listening on. Since a PHP application doesn't know which port is being used by vite, the port can be forced in the vite.config.js
file inside your project's root directory using server.strictPort
and server.port
:
For more information on how to configure Vite, see the official documentation.
ViteManifest Options
manifestPath
- string
Points to the Vite manifest.json
file created for the production build.. Optional if you're using the dev server
basePath
- string
Public base path from which Vite's published assets are served. The assets paths will be relative to the outDir
in your vite configuration. It could also point to a CDN or other asset server, if you are serving assets from a different domain.
serverUrl
- string
The vite server url, including port. Can be used to specify a non-default port if used.
devEnabled
- bool
Indicates whether the application is running in development mode (i.e. using vite server). Defaults to false.
See Also
- Changelog
- License