{"id":13607928,"url":"https://github.com/mindplay-dk/php-vite","last_synced_at":"2025-04-06T01:06:39.694Z","repository":{"id":238101802,"uuid":"791176527","full_name":"mindplay-dk/php-vite","owner":"mindplay-dk","description":"a lightweight PHP-backend integration package for Vite","archived":false,"fork":false,"pushed_at":"2024-10-08T10:43:15.000Z","size":30,"stargazers_count":43,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T00:05:51.550Z","etag":null,"topics":["php","vite"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mindplay-dk.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2024-04-24T08:27:38.000Z","updated_at":"2025-03-06T07:48:51.000Z","dependencies_parsed_at":"2024-11-17T15:10:52.488Z","dependency_job_id":"f8efefb6-cf96-4588-8635-2c68a76f76a8","html_url":"https://github.com/mindplay-dk/php-vite","commit_stats":null,"previous_names":["mindplay-dk/php-vite"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindplay-dk%2Fphp-vite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindplay-dk%2Fphp-vite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindplay-dk%2Fphp-vite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindplay-dk%2Fphp-vite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mindplay-dk","download_url":"https://codeload.github.com/mindplay-dk/php-vite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419859,"owners_count":20936012,"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":["php","vite"],"created_at":"2024-08-01T19:01:22.891Z","updated_at":"2025-04-06T01:06:39.670Z","avatar_url":"https://github.com/mindplay-dk.png","language":"PHP","funding_links":[],"categories":["Integrations with Backends"],"sub_categories":["PHP"],"readme":"# PHP-Vite\n\n[![PHP Version](https://img.shields.io/badge/php-8.1%2B-blue.svg)](https://packagist.org/packages/mindplay/php-vite)\n[![Build Status](https://github.com/mindplay-dk/php-vite/actions/workflows/ci.yml/badge.svg)](https://github.com/mindplay-dk/php-vite/actions/workflows/ci.yml)\n[![License](https://img.shields.io/badge/license-MPL--2.0-green)](https://opensource.org/license/mpl-2-0)\n\nThis library provides a lightweight [backend integration](https://vitejs.dev/guide/backend-integration.html)\nfor your PHP-based MPA, SPA, or PWA based on [Vite](https://vitejs.dev/).\n\nIt parses the [build manifest](https://vitejs.dev/config/build-options#build-manifest) (the `.vite/manifest.json` file)\nand produces the required `\u003cscript\u003e` and `\u003clink\u003e` tags to load (and preload) scripts, CSS files, and other assets.\n\n## Basic Usage\n\nA commented MPA example is available [here](https://github.com/mindplay-dk/php-vite-mpa) -\nplease refer to this for examples of configuring Vite, NPM, TypeScript, and Composer.\n\nIn the following steps, we'll cover usage of the library API only.\n\n#### 1. Load the `manifest.json` file created by Vite:\n\n```php\n$vite = new Manifest(\n    manifest_path: $your_root_dir . '/public/dist/.vite/manifest.json',\n    base_path: '/dist/',\n    dev: false\n);\n```\n\nThe `manifest_path` points to the Vite `manifest.json` file created for the production build.\n\nIn this example, `dev` is `false`, so we'll be creating tags for the production assets.\n\nThe `base_path` is relative to your public web root - it is the root folder from which Vite's production assets are served, and/or the root folder from which Vite serves assets dynamically in development mode.\n\nNote that, in development mode (when `dev` is set to `true`) the `manifest.json` file is unused, and not required.\n\n\u003e 💡 *For a detailed description of the constructor arguments, please refer to the `Manifest` constructor argument doc-blocks.*\n\n#### 2. Create the `Tags` for an entry point script:\n\n```php\n$tags = $vite-\u003ecreateTags(\"index.ts\");\n```\n\nYour entry point scripts are defined in Vite's [`build.rollupOptions`](https://vitejs.dev/config/build-options#build-rollupoptions) using RollUp's [`input`](https://rollupjs.org/configuration-options/#input) setting.\n\nNote that, if you have **multiple entry point scripts** on **the same page**, you should pass them in a *single* call - for example:\n\n```php\n$tags = $vite-\u003ecreateTags(\"index.ts\", \"consent-banner.ts\");\n```\n\nMaking multiple calls for different entry points *may* result in duplicate tags for any shared static imports - you will most likely need just *one* instance of `Tags` on a single page.\n\n#### 3. Emit from `Tags` in your HTML template:\n\nYour `Tags` instance contains the preload and CSS tags, which should be emitted in\nyour `\u003chead\u003e` tag, as well as the `js` tags, which should be emitted immediately before\nthe `\u003c/body\u003e` end tag.\n\nFor example:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003ctitle\u003eVite App\u003c/title\u003e\n    \u003clink rel=\"icon\" href=\"\u003c?= $vite-\u003egetURL(\"php.svg\") ?\u003e\" /\u003e\n    \u003c?= $tags-\u003epreload ?\u003e\n    \u003c?= $tags-\u003ecss ?\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003cdiv id=\"app\"\u003e\u003c/div\u003e\n    \u003c?= $tags-\u003ejs ?\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Preloading Assets\n\nThe service preloads any statically imported scripts and CSS files by default.\n\nIn addition, you can configure it to preload other statically imported assets as well -\nfor convenience, there are two methods to automatically configure preloading of all\ncommon image and font asset types:\n\n```php\n$manifest-\u003epreloadImages();\n$manifest-\u003epreloadFonts();\n```\n\nYou can also configure it to preload any other asset types - for example, to configure\npreloading of `.json` assets, you could add the following:\n\n```php\n$manifest-\u003epreload(\n    ext: \"json\",\n    mime_type: \"application/json\",\n    preload_as: \"fetch\"\n);\n```\n\nThen create your tags as covered in the documentation above.\n\n## Creating URLs\n\nFor advanced use cases, you can also directly get the URL for an asset published by Vite:\n\n```php\n$my_url = $manifest-\u003egetURL(\"consent-banner.ts\");\n```\n\nYou can use this feature to, for example:\n\n* Create your own custom preload tags (e.g. with media queries)\n* Conditionally load a script based on user interactions or user state, etc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmindplay-dk%2Fphp-vite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmindplay-dk%2Fphp-vite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmindplay-dk%2Fphp-vite/lists"}