PHP code example of dakujem / peat

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

    

dakujem / peat example snippets


<?= Dakujem\Peat\ViteHelper::populateDevelopmentAssets(
    entryName: 'src/main.js',
    developmentServerUrl: 'http://localhost:5173',
) 

<?= Dakujem\Peat\ViteHelper::extractAssets(
    entryName: 'src/main.js',
    manifestFile: './my-js-widget/.vite/manifest.json', // server path
    assetPathPrefix: '/my-js-widget',                   // asset URL prefix
) 

use Dakujem\Peat\ViteBridge;

$bridgeService = new ViteBridge(
    manifestFile: ROOT_DIR . '/public/my-js-widget/.vite/manifest.json',
    cacheFile: TEMP_DIR . '/vite.php',   // can be any writable file
    assetPathPrefix: '/my-js-widget',   // this value will prefix all asset URLs from the manifest
    devServerUrl: 'http://localhost:5173',
);

$locator = $bridgeService->makePassiveEntryLocator(useDevServer: $isDevelopment);
$html = (string) $locator->entry('src/main.js');

<head>
  <?= $html 

$vite = function (string $entryName) use ($locator) {
    return $locator->entry($entryName)
}

<head>
  <?= $vite('src/main.js') 

$bridgeService->populateCache();