1. Go to this page and download the library: Download stasis/ext-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/ */
stasis / ext-vite example snippets
// file: stasis.php
declare(strict_types=1);
use Stasis\Config\ConfigInterface;
use Stasis\Extension\Vite\StasisViteExtension;
use Stasis\Router\Route\Route;
use Stasis\Router\Router;
return new class implements ConfigInterface
{
private readonly StasisViteExtension $vite;
public function __construct()
{
$this->vite = StasisViteExtension::create(
assetsSourcePath: __DIR__ . '/dist_assets/assets',
manifestPath: __DIR__ . '/dist_assets/manifest.json',
assetsRoutePath: '/assets',
);
}
public function extensions(): iterable
{
return [$this->vite];
}
public function routes(): iterable
{
return [
new Route('/', $this->renderHome(...), 'home'),
];
}
private function renderHome(Router $router, array $parameters): string
{
return <<<HTML
<!DOCTYPE html>
<html>
<head>
{$this->vite->assetMapper->import('src/main.js')}
</head>
<body>
<img src="{$this->vite->assetMapper->path('src/logo.svg')}"></img>
</body>
</html>
HTML;
}
};
// file: stasis.php
declare(strict_types=1);
use Stasis\Config\ConfigInterface;
use Stasis\Extension\Vite\StasisViteExtension;
use Stasis\Router\Route\Route;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
return new class implements ConfigInterface
{
private readonly Environment $twig;
public function __construct()
{
$loader = new FilesystemLoader();
$loader->addPath(__DIR__ . '/templates');
$this->twig = new Environment($loader);
}
public function extensions(): iterable
{
return [
StasisViteExtension::create(
assetsSourcePath: __DIR__ . '/dist_assets/assets',
manifestPath: __DIR__ . '/dist_assets/manifest.json',
assetsRoutePath: '/assets',
)->withTwig($this->twig),
];
}
public function routes(): iterable
{
return [
new Route('/', fn() => $this->twig->render('home.html.twig'), 'home'),
];
}
};
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.