Skip to content

Commit 766ad16

Browse files
committed
initial check-in
0 parents  commit 766ad16

File tree

9 files changed

+705
-0
lines changed

9 files changed

+705
-0
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# https://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 4
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
13+
[*.json]
14+
indent_size = 2

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.git*
2+
!.gitignore
3+
/vendor

composer.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "mindplay/php-vite",
3+
"scripts": {
4+
"test": "php test/test.php"
5+
},
6+
"autoload": {
7+
"psr-4": {
8+
"mindplay\\vite\\": "src/"
9+
}
10+
},
11+
"require-dev": {
12+
"mindplay/testies": "^1.1"
13+
}
14+
}

composer.lock

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Chunk.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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

Comments
 (0)