idleberg / php-wordpress-vite-assets

Injects assets from a Vite manifest to the Wordpress head, supports themes and plugins
https://packagist.org/packages/idleberg/wordpress-vite-assets
MIT License
130 stars 12 forks source link

Uncaught Error: Class 'Idleberg\WordpressViteAssets\WordpressViteAssets' #4

Closed gmirmand closed 1 year ago

gmirmand commented 1 year ago

Hello ! I am absolutely no expert in the use of wordpress, composer and Vite, so my problem may be particularly simple to solve:

I would like to have a basic compilation of a single javascript file to support ES6 and a single scss file into css in a wordpress child theme. Vite (and more particularly this integration) seems to be appropriate.

I followed the instructions =

  1. composer require idleberg/wordpress-vite-assets
  2. add in my <project>/wp-content/themes/<theme-child>/functions.php

use Idleberg\WordpressViteAssets\WordpressViteAssets;

$baseUrl = get_stylesheet_directory(); $manifest = "/manifest.json"; $entryPoint = "index.ts";

$viteAssets = new WordpressViteAssets($manifest, $baseUrl); $viteAssets->addAction($entryPoint);

but on my site I get :

Fatal error: Uncaught Error: Class 'Idleberg\WordpressViteAssets\WordpressViteAssets' not found in /var/www/html//wp-content/themes//functions.php:8 Stack trace: #0 /var/www/html//wp-settings.php(555): include() #1 /var/www/html//wp-config.php(80): require_once('/var/www/html/t...') #2 /var/www/html//wp-load.php(50): require_once('/var/www/html/t...') #3 /var/www/html//wp-blog-header.php(13): require_once('/var/www/html/t...') #4 /var/www/html//index.php(17): require('/var/www/html/t...') #5 {main} thrown in /var/www/html//wp-content/themes//functions.php on line 8

So I've several questions :

Thank you very much in advance for your help and patience!

idleberg commented 1 year ago

Did you require Composer's autoloader in your functions.php? Try adding the following at the top of the file:

require_once __DIR__ . '/vendor/autoload.php';

The path of the require should reflect that of your vendor location. Usually, this is the same as in the example.

gmirmand commented 1 year ago

Nop I didn't... it's better with :) require_once ABSPATH . '/vendor/autoload.php'; I have another issue but but I'm going to create another ticket to avoid mixing up the topics. Thnaks ! :)