Skip to content

Instantly share code, notes, and snippets.

@terrylinooo
Created September 29, 2023 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terrylinooo/d0f88d699536d1b9cd00f7c683d2adf7 to your computer and use it in GitHub Desktop.
Save terrylinooo/d0f88d699536d1b9cd00f7c683d2adf7 to your computer and use it in GitHub Desktop.
functions.php
/**
* Print Vite dev server script tag.
*
* @package ironman
* @since 1.0.0
*/
function ironman_vite_dev_script() {
if (
! defined( 'VITE_ENV' ) ||
! defined( 'VITE_DEV_SERVER' ) ||
constant( 'VITE_ENV' ) !== 'development'
) {
return;
}
$entry_file = constant( 'VITE_DEV_SERVER' ) . '/vite.entry.js';
// phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
echo '<script type="module" crossorigin src="' . esc_attr( $entry_file ) . '"></script>';
}
add_action( 'wp_head', 'ironman_vite_dev_script' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment