From ad9361579d0357f0ece001e73f25314d3cea9ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20Staicu?= Date: Sun, 10 Dec 2023 14:24:08 +0200 Subject: [PATCH] Update vite-manifest.php allow custom path --- src/functions/vite-manifest.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/functions/vite-manifest.php b/src/functions/vite-manifest.php index 5b721d3..4f79b4e 100644 --- a/src/functions/vite-manifest.php +++ b/src/functions/vite-manifest.php @@ -150,14 +150,22 @@ function set_script_type_attribute(string $target_handle, string $tag, string $h */ function generate_development_asset_src(object $manifest, string $entry): string { - $origin = get_site_url() . ":{$manifest->data->port}"; + $origin = apply_filters('iamntz/wp-vite-manifest/development_assets_origin', get_home_url() . ":{$manifest->data->port}", $manifest, $entry); + + $path = apply_filters( + 'iamntz/wp-vite-manifest/development_asset_path', + trim(preg_replace('/[\/]{2,}/', '/', "{$manifest->data->base}/{$entry}"), '/'), + $manifest, $entry + ); + return sprintf( '%s/%s', untrailingslashit($origin), - trim(preg_replace('/[\/]{2,}/', '/', "{$manifest->data->base}/{$entry}"), '/') + $path ); } + /** * Register vite client script *