PHP code example of trk / processwire-vite

1. Go to this page and download the library: Download trk/processwire-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/ */

    

trk / processwire-vite example snippets


<!doctype html>
<head>
  <?= vite(['assets/css/app.css', 'assets/js/app.js']) 

<!doctype html>
<head>
  <?= vite([
    // Equivalent to this
    '@assets/css/templates/' . $page->template->name . '.css',
    '@assets/js/templates/' . $page->template->name . '.js',
  ]) 

<?= vite()->reactRefresh() 

<img src="<?= vite()->asset('assets/images/logo.png') 

setting('vite.scriptTagAttributes', [
    'data-turbo-track' => 'reload', // Specify a value for the attribute...
    'async'            => true,     // Specify a boolean attribute (renders as `async`)...
    'integrity'        => false,    // Exclude an attribute that would otherwise be 

setting('vite.scriptTagAttributes', fn (string $src, string $url, array $chunk, array $manifest) => [
    'data-turbo-track' => $src === 'assets/js/app.js' ? 'reload' : false,
]);

setting('vite.styleTagAttributes', fn (string $src, string $url, array $chunk, array $manifest) => [
    'data-turbo-track' => $chunk && $chunk['isEntry'] ? 'reload' : false,
]);

setting('vite', [
    'hotFile' => fn () => wire('config')->paths->root . 'vite.hot',
    'buildDirectory' => 'bundle',
    'manifest' => 'assets.json'
]);

vite()->instance()
    ->useHotFile(wire('config')->paths->root . 'vite.hot')
    ->useBuildDirectory('bundle')
    ->useManifest('assets.json');

<!doctype html>
<head>
  <?=
    vite()->useHotFile(wire('config')->paths->root . 'vite.hot')
          ->useBuildDirectory('bundle')
          ->useManifest('assets.json')
          ->withEntries(['assets/js/app.js'])