From 8fb19abd2584bd87d3315be06edefc204666500e Mon Sep 17 00:00:00 2001 From: Vincent Klaiber Date: Fri, 13 Sep 2024 13:35:14 +0200 Subject: [PATCH] Revert load scripts with wp_enqueue_script_module This reverts commit 52038c4af511c1c0a0a34164c3b507f6253eb6e4, which caused issues with localization and HMR. --- public/themes/wordplate/functions.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/public/themes/wordplate/functions.php b/public/themes/wordplate/functions.php index 4a1dbd7..94316b1 100644 --- a/public/themes/wordplate/functions.php +++ b/public/themes/wordplate/functions.php @@ -23,15 +23,24 @@ wp_get_environment_type() === 'local' && is_array(wp_remote_get('http://localhost:5173/')) // is Vite.js running ) { - wp_enqueue_script_module('vite', 'http://localhost:5173/@vite/client'); - wp_enqueue_script_module('wordplate', 'http://localhost:5173/resources/js/index.js'); + wp_enqueue_script('vite', 'http://localhost:5173/@vite/client'); + wp_enqueue_script('wordplate', 'http://localhost:5173/resources/js/index.js'); } elseif (file_exists($manifestPath)) { $manifest = json_decode(file_get_contents($manifestPath), true); - wp_enqueue_script_module('wordplate', get_theme_file_uri('assets/' . $manifest['resources/js/index.js']['file'])); + wp_enqueue_script('wordplate', get_theme_file_uri('assets/' . $manifest['resources/js/index.js']['file'])); wp_enqueue_style('wordplate', get_theme_file_uri('assets/' . $manifest['resources/js/index.js']['css'][0])); } }); +// Load scripts as modules. +add_filter('script_loader_tag', function (string $tag, string $handle, string $src) { + if (in_array($handle, ['vite', 'wordplate'])) { + return ''; + } + + return $tag; +}, 10, 3); + // Remove admin menu items. add_action('admin_init', function () { remove_menu_page('edit-comments.php'); // Comments