{"id":13605504,"url":"https://github.com/donnikitos/vite-plugin-php","last_synced_at":"2025-04-06T18:13:44.098Z","repository":{"id":189675630,"uuid":"613343676","full_name":"donnikitos/vite-plugin-php","owner":"donnikitos","description":"Vite's speed and tooling to preprocess PHP-files!","archived":false,"fork":false,"pushed_at":"2025-03-04T10:00:18.000Z","size":229,"stargazers_count":55,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T17:08:22.579Z","etag":null,"topics":["asset-bundling","asset-management","bundler","bundler-plugin","php","php-loader","transpiler","vite","vite-loader","vite-php","vite-plugin","vitejs"],"latest_commit_sha":null,"homepage":"https://vite-php.nititech.de/","language":"TypeScript","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/donnikitos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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":["donnikitos"],"patreon":null,"open_collective":null,"ko_fi":"donnikitos","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":"donnikitos","custom":["https://www.paypal.com/donate/?hosted_button_id=EPXZPRTR7JHDW"]}},"created_at":"2023-03-13T11:46:48.000Z","updated_at":"2025-03-18T10:24:49.000Z","dependencies_parsed_at":"2024-01-07T18:04:46.056Z","dependency_job_id":"38ed9cde-de08-4a6a-84b2-c3bd9863e846","html_url":"https://github.com/donnikitos/vite-plugin-php","commit_stats":{"total_commits":38,"total_committers":2,"mean_commits":19.0,"dds":0.3421052631578947,"last_synced_commit":"4990964db5a508172c85d856ad7483c72e0da78c"},"previous_names":["donnikitos/vite-plugin-php"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donnikitos%2Fvite-plugin-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donnikitos%2Fvite-plugin-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donnikitos%2Fvite-plugin-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donnikitos%2Fvite-plugin-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/donnikitos","download_url":"https://codeload.github.com/donnikitos/vite-plugin-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247526760,"owners_count":20953143,"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":["asset-bundling","asset-management","bundler","bundler-plugin","php","php-loader","transpiler","vite","vite-loader","vite-php","vite-plugin","vitejs"],"created_at":"2024-08-01T19:00:59.546Z","updated_at":"2025-04-06T18:13:44.075Z","avatar_url":"https://github.com/donnikitos.png","language":"TypeScript","readme":"\u003cp align=\"center\" style=\"text-align: center;\"\u003e\n\t\u003cimg\n\tsrc=\"https://vite-php.nititech.de/assets/vite-php.logo.svg\"\n\talt=\"vite-plugin-php logo\"\n\tstyle=\"width: 250px; max-width: 100%;\" /\u003e\n\u003c/p\u003e\n\n\u003cdiv style=\"display: grid; grid-template-columns: max-content max-content; column-gap: 10px;\"\u003e\n\t\u003ca href=\"https://github.com/donnikitos/vite-plugin-php/blob/master/LICENSE\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/github/license/donnikitos/vite-plugin-php?color=blue\u0026style=for-the-badge\" alt=\"License\" /\u003e\u003c/a\u003e\n\t\u003cdiv\u003e\u003c/div\u003e\n\t\u003ca href=\"https://www.npmjs.com/package/vite-plugin-php\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/npm/dt/vite-plugin-php?style=for-the-badge\" alt=\"NPM\" /\u003e\u003c/a\u003e\n\t\u003ca href=\"https://github.com/donnikitos/vite-plugin-php\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/donnikitos/vite-plugin-php?label=GitHub%20Stars\u0026style=for-the-badge\" alt=\"GitHub Stars\" /\u003e\u003c/a\u003e\n\t\u003ca href=\"https://github.com/donnikitos/vite-plugin-php/issues\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/github/issues/donnikitos/vite-plugin-php?style=for-the-badge\" alt=\"Issues\" /\u003e\u003c/a\u003e\n\t\u003cimg src=\"https://img.shields.io/github/last-commit/donnikitos/vite-plugin-php?style=for-the-badge\" alt=\"Last Commit\" /\u003e\n\u003c/div\u003e\n\n\\\nUse Vite's speed and tooling to work with PHP!\n\n```js\n// vite.config.js\nimport { defineConfig } from 'vite';\nimport usePHP from 'vite-plugin-php';\n\nexport default defineConfig({\n\tplugins: [usePHP()],\n});\n```\n\n\u003cp align=\"center\" style=\"text-align: center;\"\u003e\n\t\u003cb\u003e\n\t\t\u003ca href=\"https://www.npmjs.com/package/vite-plugin-php\"\u003eNPM\u003c/a\u003e | \u003ca href=\"https://vite-php.nititech.de/\"\u003eWiki\u003c/a\u003e | \u003ca href=\"https://github.com/donnikitos/vite-plugin-php/discussions\"\u003eDiscussions\u003c/a\u003e | \u003ca href=\"https://github.com/nititech/php-vite-starter\"\u003eStarter-Repo\u003c/a\u003e\n\t\u003c/b\u003e\n\u003c/p\u003e\n\n## ⚡ Latest changes\n\n##### Major Release 2.0.0 !!!\n\nIncluding full _PHP error logging_ into console, rewritten code for _better performance_, bug fixes, etc.\\\n[See changelog](https://vite-php.nititech.de/changelog).\n\n##### Releases \u003e= 1.0.0\n\n| Version | Feature                                                          |\n| ------- | ---------------------------------------------------------------- |\n| 1.0.71  | Fixed assets prepending for namespaced PHP-files                 |\n| 1.0.70  | Added include path override for relative PHP imports in dev mode |\n| 1.0.69  | Using new token format to escape PHP in HTML                     |\n| 1.0.68  | Improved transpiled code evaluation (removed native `eval()`)    |\n| ...     | ...                                                              |\n\n## Write some PHP code in your `index.php`\n\n```php\n\u003c!-- index.php --\u003e\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\t\u003chead\u003e\n\t\t\u003cmeta charset=\"UTF-8\" /\u003e\n\t\t\u003cmeta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" /\u003e\n\t\t\u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n\t\u003c/head\u003e\n\t\u003cbody\u003e\n\t\t\u003cdiv id=\"root\"\u003e\n\t\t\t\u003c?=\"Render some text with PHP!\"; ?\u003e\n\t\t\u003c/div\u003e\n\n\t\t\u003c?php if(isset($_GET['show_hello'])): ?\u003e\n\t\t\tHello world!\n\t\t\u003c?php endif; ?\u003e\n\n\t\t\u003cscript src=\"./src/react-app.tsx\" type=\"module\"\u003e\u003c/script\u003e\n\t\u003c/body\u003e\n\u003c/html\u003e\n```\n\nThe plugin will serve you the processed `index.php` as usual, including all imported and preprocessed files that are supported by Vite and other loaders.\n\n## Configuration\n\nThe configuration takes following properties:\n\n```ts\ntype UsePHPConfig = {\n\tbinary?: string;\n\tentry?: string | string[];\n\trewriteUrl?: (requestUrl: URL) =\u003e URL | undefined;\n\ttempDir?: string;\n\tdev?: {\n\t\t// Takes on either a bitmask, or named constants EPHPError\n\t\terrorLevels?: number;\n\t\tcleanup?: boolean;\n\t};\n};\n\n// Detailed description on https://www.php.net/manual/en/errorfunc.constants.php\nconst EPHPError = {\n\tERROR: 1,\n\tWARNING: 2,\n\tPARSE: 4,\n\tNOTICE: 8,\n\tCORE_ERROR: 16,\n\tCORE_WARNING: 32,\n\tCOMPILE_ERROR: 64,\n\tCOMPILE_WARNING: 128,\n\tUSER_ERROR: 256,\n\tUSER_WARNING: 512,\n\tUSER_NOTICE: 1024,\n\tSTRICT: 2048,\n\tRECOVERABLE_ERROR: 4096,\n\tDEPRECATED: 8192,\n\tUSER_DEPRECATED: 16384,\n\tALL: 32767,\n};\n```\n\nBy default the plugin is trying to access the system `php`-binary and load the `index.php` file as the main entry point.\n\n#### Alternative entry points\n\nHowever you have the possibility to use an other binary or even compile multiple entry-points:\n\n```js\nusePHP({\n\tbinary: '/opt/lampp/bin/php-8.1.10',\n\tentry: ['index.php', 'index_alt.php', 'pages/contact.php'],\n});\n```\n\nShould you have multiple entry-points, you will be able to access each one according to this chart:\n\n| Entry file        | Accessible routes                     | Build file          |\n| ----------------- | ------------------------------------- | ------------------- |\n| index.php         | `/` `/index` `/index.php`             | `index.php`         |\n| about.php         | `/about` `/about.php`                 | `about.php`         |\n| about/details.php | `/about/details` `/about/details.php` | `about/details.php` |\n| contact.php       | `/contact` `/contact.php`             | `contact.php`       |\n| shop/index.php    | `/shop/` `/shop/index.php`            | `shop/index.php`    |\n| ...               | ...                                   | ...                 |\n\nYou can also specify wildcard entry points:\n\n```js\nusePHP({\n\tbinary: '/opt/lampp/bin/php-8.1.10',\n\tentry: [\n\t\t'index.php',\n\t\t'about.php',\n\t\t'contact.php',\n\t\t'pages/**/*.php',\n\t\t'partials/*.php',\n\t],\n});\n```\n\nThese entries will also render according to the routing table above.\n\n#### Rewrite urls\n\nIf you are using some sort of Apaches _mod_rewrite_ magic or nginx rewrite rules you can simulate them with the newly added in `rewriteUrl` property.\nThe rewriteUrl function has one parameter - the requested URL given as URL object - and return either a modified URL object or undefined:\n\n```js\nusePHP({\n\tentry: ['index.php', 'partials/**/*.php'],\n\trewriteUrl(requestUrl) {\n\t\tif (['.js', '.css'].some((s) =\u003e requestUrl.pathname.includes(s))) {\n\t\t\treturn;\n\t\t}\n\n\t\trequestUrl.search = '_request_=' + requestUrl.pathname;\n\t\trequestUrl.pathname = 'index.php';\n\n\t\treturn requestUrl;\n\t},\n});\n```\n\n⚠️ **Attention:** If using the rewriteUrl property you will need to exclude (_return undefined_) assets like CSS, JavaScript, Images, etc.., that match your transpiled php file names, on your own!\n\n#### Error logging\n\nJust like in native PHP you can specify what errors you want to see:\n\n```js\n// vite.config.js\nimport { defineConfig } from 'vite';\nimport usePHP, { EPHPError } from 'vite-plugin-php';\n\nexport default defineConfig({\n\tplugins: [\n\t\tusePHP({\n\t\t\tdev: {\n\t\t\t\terrorLevels:\n\t\t\t\t\tEPHPError.ERROR | EPHPError.WARNING | EPHPError.STRICT,\n\t\t\t},\n\t\t}),\n\t],\n});\n```\n\nThis log will be printed into your console, just like any other message about what is happening in Vite.\\\nFor more details about the meaning of the error level constants, visit the original [PHP-documentation](https://www.php.net/manual/en/errorfunc.constants.php).\n\n## Specific oddities\n\n#### Inline modules\n\n⚠️ PHP will work somehow unintuitive in inlined modules.\nE.g. you have a page with some variables:\n\n```php\n\u003c?php\n$var = 'foo';\n?\u003e\n\n\u003cscript type=\"module\"\u003e\n\tconsole.log('\u003c?=$var; ?\u003e');\n\u003c/script\u003e\n```\n\nThis will not work. `$var` will be undefined in the module since the script is being transpiled into a separate file and included separately.\nSame applies to other server variables like `$_GET`, `$_POST` and so on - they will not have the same value as the main PHP file.\n\n#### Dynamically included asset processing\n\nVite won't be able to process PHP-computed styles, scripts or images:\n\n```php\n\u003cscript src=\"./src/\u003c?='dynamic_script_name'; ?\u003e.js\" type=\"module\"\u003e\u003c/script\u003e\n```\n\n#### Conditional script and style loading\n\nThe plugin won't be able to retain the position of some asset tags like `\u003cscript\u003e` and `\u003clink\u003e`.\n\n```php\n\u003c?php if($some_condition$) { ?\u003e\n\t\u003cscript src=\"./src/some_script.js\" type=\"module\"\u003e\u003c/script\u003e\n\u003c?php } ?\u003e\n```\n\nVite processes these independently and merges/ splits them dynamically.\\\nThese will be attached to the `\u003chead\u003e` tag or put right in the beginning of the file.\n\nIf the file contains a PHP **namespace** the assets will be either\\\na) placed after the last closed tag\\\nb) placed right before the last `\u003c?` tag\\\nc) placed at the end of the file\n\n## Issues\n\nIf you encounter any other bugs or need some other features feel free to open an [issue](https://github.com/donnikitos/vite-plugin-php/issues).\n\n## Support\n\nLove open source? Enjoying my project?\\\nYour support can keep the momentum going! Consider a donation to fuel the creation of more innovative open source software.\n\n\u003ctable\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd\u003e\n\t\t\tvia Ko-Fi\n\t\t\u003c/td\u003e\n\t\t\u003ctd\u003e\n\t\t\tBuy me a coffee\n\t\t\u003c/td\u003e\n\t\t\u003ctd\u003e\n\t\t\tvia PayPal\n\t\t\u003c/td\u003e\n\t\u003c/tr\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd\u003e\n\t\t\t\u003ca href=\"https://ko-fi.com/Y8Y2ALMG\" target=\"_blank\"\u003e\u003cimg src=\"https://ko-fi.com/img/githubbutton_sm.svg\" alt=\"Ko-Fi\" width=\"174\"\u003e\u003c/a\u003e\n\t\t\u003c/td\u003e\n\t\t\u003ctd\u003e\n\t\t\t\u003ca href=\"https://www.buymeacoffee.com/donnikitos\" target=\"_blank\"\u003e\u003cimg src=\"https://nititech.de/donate-buymeacoffee.png\" alt=\"Buy Me A Coffee\" width=\"174\"\u003e\u003c/a\u003e\n\t\t\u003c/td\u003e\n\t\t\u003ctd\u003e\n\t\t\t\u003ca href=\"https://www.paypal.com/donate/?hosted_button_id=EPXZPRTR7JHDW\" target=\"_blank\"\u003e\u003cimg src=\"https://nititech.de/donate-paypal.png\" alt=\"PayPal\" width=\"174\"\u003e\u003c/a\u003e\n\t\t\u003c/td\u003e\n\t\u003c/tr\u003e\n\u003c/table\u003e\n","funding_links":["https://github.com/sponsors/donnikitos","https://ko-fi.com/donnikitos","https://buymeacoffee.com/donnikitos","https://www.paypal.com/donate/?hosted_button_id=EPXZPRTR7JHDW","https://ko-fi.com/Y8Y2ALMG","https://www.buymeacoffee.com/donnikitos"],"categories":["Plugins"],"sub_categories":["Framework-agnostic Plugins"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonnikitos%2Fvite-plugin-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdonnikitos%2Fvite-plugin-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonnikitos%2Fvite-plugin-php/lists"}