WordPress Utilities
kaiseki/wp-inpsyde-assets
Companion module for inpsyde/assets that registers a Vite
build’s manifest.json entries as WordPress assets and wires up a Vite dev-server client.
It provides:
ViteManifestLoader— aninpsyde/assetswebpack-style loader that parses a Vitemanifest.jsonintoScript/Styleassets (by extension), with optional handle prefixing and a configurable directory URL.ViteManifestRegistry— akaiseki/wp-hookHookProviderInterfacethat, on theinpsyde/assetssetup action, loads the configured manifests, applies per-handle script/style filters, optionally tags scripts as ES modules, and registers them with theAssetManager.ViteClient— injects the@vite/clientdev script into the page when the Vite dev server is running (detected on local/development environments viakaiseki/wp-env).
Installation
composer require kaiseki/wp-inpsyde-assets
Requires PHP 8.2 or newer.
Usage
Register ConfigProvider with your laminas-style config aggregator and activate the providers via
kaiseki/wp-hook. Configure the manifests and the dev-server client under their config keys:
use Kaiseki\WordPress\InpsydeAssets\Registry\ViteManifestRegistry;
use Kaiseki\WordPress\InpsydeAssets\ViteClient\ViteClient;
return [
'vite_client' => [
'host' => 'localhost',
'port' => 5173,
],
'vite_manifest' => [
// list of manifest.json paths, or callables receiving the ViteClient
'files' => [get_theme_file_path('dist/manifest.json')],
'autoload' => true,
'handle_prefix' => 'theme-',
'es_modules' => true,
// optional per-handle filters: handle => callable|bool
'scripts' => [],
'styles' => [],
],
'hook' => [
'provider' => [
ViteClient::class,
ViteManifestRegistry::class,
],
],
];
VITE_HOST and VITE_PORT environment variables override the configured dev-server host/port.
Development
composer install
composer check # check-deps, cs-check, phpstan
License
MIT — see LICENSE.