承接 millancore/vite-manifest 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

millancore/vite-manifest

最新稳定版本:v0.1.0

Composer 安装命令:

composer require millancore/vite-manifest

包简介

PHP Vite Manifest Manager

README 文档

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.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-23