Skip to content

Commit

Permalink
Revert load scripts with wp_enqueue_script_module
Browse files Browse the repository at this point in the history
This reverts commit 52038c4, which caused issues with localization and HMR.
  • Loading branch information
vinkla committed Sep 13, 2024
1 parent 17a9020 commit 8fb19ab
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions public/themes/wordplate/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<script type="module" src="' . esc_url($src) . '" defer></script>';
}

return $tag;
}, 10, 3);

// Remove admin menu items.
add_action('admin_init', function () {
remove_menu_page('edit-comments.php'); // Comments
Expand Down

0 comments on commit 8fb19ab

Please sign in to comment.