PHP code example of juster / wordpress-vite

1. Go to this page and download the library: Download juster/wordpress-vite library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

juster / wordpress-vite example snippets


use Juster\WordpressVite\App;

function vite(): App
{
    return App::get(ABSPATH, WP_ENVIRONMENT_TYPE);
}

vite();

function theme(): void
{
    vite()->assets()->enqueueStyle('theme', 'src/styles/main.css');
    vite()->assets()->enqueueScript('theme', 'src/scripts/main.js');
}

add_action('wp_enqueue_scripts', 'theme');

function asset($path): string
{
    return vite()->assets()->resolve("src/assets/$path");
}
html
<img
  src="<?= vite()->assets()->resolve('src/assets/images/placeholder.webp') 
html
<img src="<?= asset('images/placeholder.webp')