laravite/manifest

Framework-agnostic library for parsing Vite manifest files

v1.0 2022-03-09 18:40 UTC

This package is auto-updated.

Last update: 2023-04-28 20:02:18 UTC


README

License Packagist PHP Version Support Packagist Downloads GitHub Workflow Status

Manifest is a framework-agnostic PHP library for parsing Vite manifest files.

Installation

Manifest is distributed via Packagist and can be installed with Composer.

composer require laravite/manifest

Usage

Manifest is straightforward to use.

// Parse a JSON-encoded manifest
$manifest = Manifest::parse($json);

// Retrieve entries
$allEntries = $manifest->entries;
$mainEntry = $manifest->entry('main.js');

// Retrieve chunks
$allChunks = $manifest->chunks;
$mainChunk = $manifest->chunk('main.js');

Chunk objects expose the following properties file, isEntry, isDynamicEntry, src, css, assets, imports, dynamicImports. Most of these properties are actually optional, and will return null if they are not present on the chunk.

If the chunks of the parsed manifest contain additional fields, they will also be exposed on the Chunk object. This make Manifest compatible with plugins that extend the original manifest file.

Manifest validation

Manifest can optionally validate the Vite manifest against its JSON schema to ensure that it is valid. To enable validation, install the suggested opis/json-schema package and pass true to the validate parameter.

$manifest = Manifest::parse($json, validate: true);

License

Manifest is open-sourced software licensed under the MIT license.