{"id":19316234,"url":"https://github.com/userfrosting/vite-php-twig","last_synced_at":"2025-03-01T04:24:11.797Z","repository":{"id":246710168,"uuid":"821945045","full_name":"userfrosting/vite-php-twig","owner":"userfrosting","description":"Vite Manifest Support for PHP \u0026 Twig","archived":false,"fork":false,"pushed_at":"2024-07-04T14:19:16.000Z","size":24,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-12T02:32:12.221Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/userfrosting.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":"userfrosting","ko_fi":"lcharette","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2024-06-29T21:54:42.000Z","updated_at":"2024-08-15T15:08:20.000Z","dependencies_parsed_at":"2024-07-05T23:07:59.813Z","dependency_job_id":null,"html_url":"https://github.com/userfrosting/vite-php-twig","commit_stats":null,"previous_names":["userfrosting/vite-php-twig"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/userfrosting%2Fvite-php-twig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/userfrosting%2Fvite-php-twig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/userfrosting%2Fvite-php-twig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/userfrosting%2Fvite-php-twig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/userfrosting","download_url":"https://codeload.github.com/userfrosting/vite-php-twig/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241315562,"owners_count":19942860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T01:10:33.855Z","updated_at":"2025-03-01T04:24:11.775Z","avatar_url":"https://github.com/userfrosting.png","language":"PHP","funding_links":["https://opencollective.com/userfrosting","https://ko-fi.com/lcharette"],"categories":[],"sub_categories":[],"readme":"# Vite Manifest Support for PHP \u0026 Twig\n\n[![Version](https://img.shields.io/github/v/release/userfrosting/vite-php-twig?sort=semver)](https://github.com/userfrosting/vite-php-twig/releases)\n![PHP Version](https://img.shields.io/badge/php-%5E8.1-brightgreen)\n[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)\n[![Build](https://img.shields.io/github/actions/workflow/status/userfrosting/vite-php-twig/Build.yml?logo=github)](https://github.com/userfrosting/vite-php-twig/actions)\n[![Codecov](https://codecov.io/gh/userfrosting/vite-php-twig/branch/main/graph/badge.svg)](https://app.codecov.io/gh/userfrosting/vite-php-twig/branch/main)\n[![StyleCI](https://github.styleci.io/repos/821945045/shield?branch=main\u0026style=flat)](https://github.styleci.io/repos/821945045)\n[![PHPStan](https://img.shields.io/github/actions/workflow/status/userfrosting/vite-php-twig/PHPStan.yml?label=PHPStan)](https://github.com/userfrosting/vite-php-twig/actions/workflows/PHPStan.yml)\n[![Donate](https://img.shields.io/badge/Donate-Buy%20Me%20a%20Coffee-blue.svg)](https://ko-fi.com/lcharette)\n\nVite Manifest function for PHP \u0026 Twig Templates. Allows [Vite manifest](https://vitejs.dev/guide/backend-integration) integration in PHP \u0026 Twig Templates without Symfony. Optimized for PHP-DI style containers.\n\nInspired by [kellerkinderDE/vite-encore-bundle](https://github.com/kellerkinderDE/vite-encore-bundle) \u0026 [PHP-Vite](https://github.com/mindplay-dk/php-vite). \n\n## Installation\n```\ncomposer require userfrosting/vite-php-twig\n```\n\n## Documentation \u0026 Usage\n### Using standalone\n\n```php\n$manifest = new ViteManifest('.vite/manifest.json');\n\n// Get files for `views/foo.js` entry\n$manifest-\u003egetScripts('views/foo.js'); // Scripts\n$manifest-\u003egetStyles('views/foo.js'); // Style\n$manifest-\u003egetImports('views/foo.js'); // Preload\n\n// Render HTML tags for `views/foo.js` entry\n$manifest-\u003erenderScripts('views/foo.js'); // Scripts\n$manifest-\u003erenderStyles('views/foo.js'); // Style\n$manifest-\u003erenderPreloads('views/foo.js'); // Preload\n\n// If you have multiple entry point scripts on the same page, you should pass them in a single call to avoid duplicates - for example:\n$manifest-\u003egetScripts('views/foo.js', 'views/bar.js');\n```\n\n\u003e `ViteManifest` implements `\\UserFrosting\\ViteTwig\\ViteManifestInterface` if you prefer to type-hint against interfaces, for use with dependency injection.\n\n### Using with Twig\n\u003e Requires Twig 3 or newer\n\nVite 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`, \n\n```php\nuse UserFrosting\\ViteTwig\\ViteManifest;\nuse Twig\\Environment;\nuse Twig\\Loader\\FilesystemLoader;\n\n$manifest = new ViteManifest('.vite/manifest.json');\n$extension = new ViteTwigExtension($manifest);\n\n// Create Twig Environment and add extension\n$loader = new FilesystemLoader('./path/to/templates');\n$twig = new Environment($loader);\n$twig-\u003eaddExtension($extension);\n```\n\nNow, to render all of the `script` and `link` tags for a specific \"entry\" (e.g. `entry1`), you can:\n\n```twig\n{{ vite_js('views/foo.js') }}\n{{ vite_css('views/foo.js') }}\n{{ vite_preload('views/foo.js') }}\n```\n\nIf you have multiple entry point scripts on the same page, you should pass them in a single call to avoid duplicates - for example:\n```twig\n{{ vite_js('views/foo.js', 'views/bar.js') }}\n```\n\n### Vite default port\nBy 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`](https://vitejs.dev/config/server-options#server-strictport) and [`server.port`](https://vitejs.dev/config/server-options#server-port) :  \n```js\nserver: {\n    strictPort: true,\n    port: 3000,\n},\n```\nFor more information on how to configure Vite, see the [official documentation](https://vitejs.dev/config/).\n\n### ViteManifest Options\n\n```php\n$manifest = new ViteManifest(\n    manifestPath: '.vite/manifest.json',\n    basePath: 'dist/',\n    serverUrl: 'http://[::1]:5173/',\n    devEnabled: true,\n)\n```\n\n`manifestPath` - string\n\nPoints to the Vite `manifest.json` file created for the production build.. Optional if you're using the dev server\n\n`basePath` - string \n\nPublic 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.\n\n``serverUrl`` - string \n\nThe vite server url, including port. Can be used to specify a non-default port if used.\n\n``devEnabled`` - bool\n\nIndicates whether the application is running in development mode (i.e. using vite server). Defaults to false.\n\n## See Also\n- [Changelog](CHANGELOG.md)\n- [License](LICENSE)\n\n## References\n- [Vite manifest](https://vitejs.dev/guide/backend-integration)\n- [kellerkinderDE/vite-encore-bundle](https://github.com/kellerkinderDE/vite-encore-bundle)\n- [PHP-Vite](https://github.com/mindplay-dk/php-vite)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuserfrosting%2Fvite-php-twig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuserfrosting%2Fvite-php-twig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuserfrosting%2Fvite-php-twig/lists"}