|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace mindplay\vite; |
| 4 | + |
| 5 | +/** |
| 6 | + * This class represents a chunk of Vite's `manifest.json` file, which contains |
| 7 | + * records of all published files, their dependencies, and other metadata. |
| 8 | + * |
| 9 | + * @see https://github.com/vitejs/vite/blob/e7adcf0878bd7f3c0b7bb5c9a1d7e6f0d55d9650/packages/vite/src/node/plugins/manifest.ts#L18-L28 |
| 10 | + */ |
| 11 | +class Chunk |
| 12 | +{ |
| 13 | + public function __construct( |
| 14 | + /** |
| 15 | + * Path to the source file, relative to Vite's `root`. |
| 16 | + */ |
| 17 | + public readonly ?string $src, |
| 18 | + |
| 19 | + /** |
| 20 | + * Logical chunk name, as defined by Rollup. |
| 21 | + * |
| 22 | + * Only defined for chunks that are entry points. |
| 23 | + * |
| 24 | + * Vite's `build.rollupOptions.input` setting affects this value - you |
| 25 | + * can define a custom chunk name for each entry point by using an |
| 26 | + * object instead of an array. |
| 27 | + * |
| 28 | + * @link https://rollupjs.org/configuration-options/#input |
| 29 | + */ |
| 30 | + public readonly ?string $name, |
| 31 | + |
| 32 | + /** |
| 33 | + * Indicates whether this chunk is an entry point. |
| 34 | + */ |
| 35 | + public readonly bool $isEntry, |
| 36 | + |
| 37 | + /** |
| 38 | + * Indicates whether this chunk is a dynamic entry point. |
| 39 | + */ |
| 40 | + public readonly bool $isDynamicEntry, |
| 41 | + |
| 42 | + /** |
| 43 | + * Path to the published file, relative to Vite's `build.outDir`. |
| 44 | + */ |
| 45 | + public readonly string $file, |
| 46 | + |
| 47 | + /** |
| 48 | + * Paths to published CSS files imported by this chunk, |
| 49 | + * relative to Vite's `build.outDir`. |
| 50 | + * |
| 51 | + * @var string[] |
| 52 | + */ |
| 53 | + public readonly array $css, |
| 54 | + |
| 55 | + /** |
| 56 | + * Paths to published assets imported by this chunk, |
| 57 | + * relative to Vite's `build.outDir`. |
| 58 | + * |
| 59 | + * @var string[] |
| 60 | + */ |
| 61 | + public readonly array $assets, |
| 62 | + |
| 63 | + /** |
| 64 | + * List of chunk names of other chunks (statically) imported by this chunk. |
| 65 | + * |
| 66 | + * @var string[] |
| 67 | + */ |
| 68 | + public readonly array $imports, |
| 69 | + |
| 70 | + /** |
| 71 | + * Links of chunk names of other chunks (dynamically) imported by this chunk. |
| 72 | + * |
| 73 | + * @var string[] |
| 74 | + */ |
| 75 | + public readonly array $dynamicImports, |
| 76 | + ) { |
| 77 | + } |
| 78 | + |
| 79 | + public static function create(array $chunk): self |
| 80 | + { |
| 81 | + return new self( |
| 82 | + src: $chunk['src'] ?? null, |
| 83 | + name: $chunk['name'] ?? null, |
| 84 | + isEntry: $chunk['isEntry'] ?? false, |
| 85 | + isDynamicEntry: $chunk['isDynamicEntry'] ?? false, |
| 86 | + file: $chunk['file'], |
| 87 | + css: $chunk['css'] ?? [], |
| 88 | + assets: $chunk['assets'] ?? [], |
| 89 | + imports: $chunk['imports'] ?? [], |
| 90 | + dynamicImports: $chunk['dynamicImports'] ?? [], |
| 91 | + ); |
| 92 | + } |
| 93 | +} |
0 commit comments