millancore/vite-manifest

PHP Vite Manifest Manager

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/millancore/vite-manifest

v0.1.0 2025-09-23 13:53 UTC

This package is auto-updated.

Last update: 2025-09-23 13:58:15 UTC


README

A PHP library for managing Vite asset manifests and generating HTML tags for JavaScript and CSS assets.

This library was created inspired by the Laravel Vite implementation, providing a similar API for PHP applications to integrate Vite-built assets.

Requirements

  • PHP 8.2 or higher

Installation

Install the library via Composer:

composer require millancore/vite-manifest

Usage

Basic Usage

Create a new ViteManager instance and invoke it with your entry points:

use Millancore\Vite\ViteManager;

$vite = new ViteManager();
$vite->setBuildDirectory('public/build'); // Optional, defaults to 'build'

echo $vite(['resources/js/app.js', 'resources/css/app.css']);

This will generate the necessary <script>, <link>, and <link rel="preload"> tags for your assets.

Configuration

Build Directory

Set the build directory where Vite outputs your assets:

$vite->setBuildDirectory('dist');

Manifest Filename

Customize the manifest filename (defaults to manifest.json):

$vite->setManifestFilename('vite-manifest.json');

Hot Module Replacement (HMR)

For development with HMR, set the hot file path:

$vite->setHotFile('public/hot');

Content Security Policy (CSP) Nonce

Add a nonce for CSP:

$vite->setNonce('your-nonce-value');

Subresource Integrity

Enable SRI with a key:

$vite->setIntegrityKey('your-integrity-key');

Custom Resolvers

Add custom resolvers for scripts, styles, or preloads:

$vite->addScriptResolver(function ($url, $chunk, $manifest) {
    // Custom script tag logic
    return '<script src="' . $url . '" defer></script>';
});

$vite->addStyleResolver(function ($url, $chunk, $manifest) {
    // Custom style tag logic
    return '<link rel="stylesheet" href="' . $url . '">';
});

$vite->addPreloadResolver(function ($url, $chunk, $manifest) {
    // Custom preload tag logic
    return '<link rel="preload" href="' . $url . '" as="script">';
});

Asset Path Resolver

Customize how asset paths are resolved:

$vite->setAssetPathResolver(function ($path) {
    return 'https://cdn.example.com/' . $path;
});

Features

  • Automatic generation of HTML tags for Vite-built assets
  • Support for Hot Module Replacement (HMR) in development
  • Content Security Policy (CSP) nonce support
  • Subresource Integrity (SRI) support
  • Customizable asset path resolution
  • Extensible tag generation with resolvers
  • PSR-4 autoloading

License

This library is licensed under the MIT License. See the LICENSE file for details.