{"id":30107053,"url":"https://github.com/benignware/vite-plugin-wordpress","last_synced_at":"2025-08-10T01:33:01.896Z","repository":{"id":288470001,"uuid":"968213411","full_name":"benignware/vite-plugin-wordpress","owner":"benignware","description":"A vite plugin for dealing with @wordpress packages","archived":false,"fork":false,"pushed_at":"2025-04-17T17:53:07.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-18T08:07:50.626Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benignware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2025-04-17T17:37:20.000Z","updated_at":"2025-04-17T17:53:10.000Z","dependencies_parsed_at":"2025-04-21T06:16:20.348Z","dependency_job_id":null,"html_url":"https://github.com/benignware/vite-plugin-wordpress","commit_stats":null,"previous_names":["benignware/vite-plugin-wordpress"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/benignware/vite-plugin-wordpress","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Fvite-plugin-wordpress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Fvite-plugin-wordpress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Fvite-plugin-wordpress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Fvite-plugin-wordpress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benignware","download_url":"https://codeload.github.com/benignware/vite-plugin-wordpress/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Fvite-plugin-wordpress/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269663320,"owners_count":24455798,"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","status":"online","status_checked_at":"2025-08-09T02:00:10.424Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-08-10T01:32:05.896Z","updated_at":"2025-08-10T01:33:01.842Z","avatar_url":"https://github.com/benignware.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vite-plugin-wordpress\n\nThis Vite plugin externalizes WordPress dependencies and generates a `*.asset.php` manifest file during the build process. It is specifically designed for WordPress projects that require a separation between their build assets and WordPress environment, enabling seamless integration with the WordPress ecosystem.\n\n## Features\n\n- **Externalizes WordPress dependencies**: Automatically replaces imports for `@wordpress/*` packages with `wp.*` globals.\n- **Generates a WordPress asset manifest**: Outputs a PHP file (`*.asset.php`) containing dependencies and version information based on your build output.\n- **Customizable manifest generation**: The asset manifest can be generated optionally using the plugin options.\n  \n## Installation\n\nTo install the plugin, run the following command:\n\n```bash\nnpm install vite-plugin-wordpress-externals --save-dev\n```\n\n## Configuration\n\nIn your `vite.config.js` (or `vite.config.ts`), add the plugin to your Vite configuration:\n\n```javascript\nimport wordpressExternalsPlugin from 'vite-plugin-wordpress-externals';\n\nexport default {\n  plugins: [\n    wordpressExternalsPlugin(),\n  ],\n};\n```\n\n### Plugin Options\n\n- `manifest`: (default `true`) - Set to `false` to skip generating the asset manifest file. If enabled, a PHP file (`*.asset.php`) is generated for each JavaScript entry chunk in the `dist` directory.\n\n## How It Works\n\nThe plugin works by detecting all WordPress dependencies (`@wordpress/*`) defined in your `package.json`. It then replaces import statements for these dependencies with references to global `wp.*` variables, as they are available in the WordPress environment.\n\n- **Imports**: The plugin replaces imports like `import { element } from '@wordpress/element'` with `const { element } = wp.element;`.\n- **Globals**: It ensures that these dependencies are marked as external in the Rollup build process and maps them to the corresponding `wp.*` global variables.\n- **Asset Manifest**: The plugin creates a PHP manifest for each JS entry file, listing the WordPress dependencies used and a hash of the file's content.\n\n## Generated PHP Asset Manifest\n\nThe plugin generates a `*.asset.php` file for each JavaScript chunk that looks like this:\n\n```php\n\u003c?php return [\n  'dependencies' =\u003e ['wp-element', 'wp-hooks'],\n  'version' =\u003e 'abcd1234',\n];\n```\n\n- **`dependencies`**: Lists the WordPress dependencies used by the chunk (e.g., `wp-element`, `wp-hooks`).\n- **`version`**: A unique version hash based on the chunk's content.\n\nThe asset manifest can be included in your WordPress theme or plugin to properly enqueue the generated JavaScript file with the correct dependencies and version.\n\n## Example\n\nIf you have an entry file that imports WordPress packages:\n\n```javascript\nimport { element } from '@wordpress/element';\nimport { hooks } from '@wordpress/hooks';\n```\n\nThe plugin will replace those imports with:\n\n```javascript\nconst { element } = wp.element;\nconst { hooks } = wp.hooks;\n```\n\nAdditionally, it will generate a `*.asset.php` manifest with the dependencies:\n\n```php\n\u003c?php return [\n  'dependencies' =\u003e ['wp-element', 'wp-hooks'],\n  'version' =\u003e 'abcd1234',\n];\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenignware%2Fvite-plugin-wordpress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenignware%2Fvite-plugin-wordpress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenignware%2Fvite-plugin-wordpress/lists"}