|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Vite plugin for Craft CMS |
|
4
|
|
|
* |
|
5
|
|
|
* Allows the use of the Vite.js next generation frontend tooling with Craft CMS |
|
6
|
|
|
* |
|
7
|
|
|
* @link https://nystudio107.com |
|
|
|
|
|
|
8
|
|
|
* @copyright Copyright (c) 2021 nystudio107 |
|
|
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace nystudio107\vite\models; |
|
12
|
|
|
|
|
13
|
|
|
use craft\base\Model; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
|
|
|
|
|
16
|
|
|
* @author nystudio107 |
|
|
|
|
|
|
17
|
|
|
* @package Vite |
|
|
|
|
|
|
18
|
|
|
* @since 1.0.0 |
|
|
|
|
|
|
19
|
|
|
*/ |
|
|
|
|
|
|
20
|
|
|
class Settings extends Model |
|
21
|
|
|
{ |
|
22
|
|
|
// Public Properties |
|
23
|
|
|
// ========================================================================= |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
|
|
|
|
|
26
|
|
|
* @var bool Should the dev server be used for? |
|
27
|
|
|
*/ |
|
28
|
|
|
public bool $useDevServer = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
|
|
|
|
|
31
|
|
|
* @var string File system path (or URL) to the Vite-built manifest.json |
|
32
|
|
|
*/ |
|
33
|
|
|
public string $manifestPath = ''; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
|
|
|
|
|
36
|
|
|
* @var string The public URL to the dev server (what appears in `<script src="">` tags |
|
37
|
|
|
*/ |
|
38
|
|
|
public string $devServerPublic = ''; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
|
|
|
|
|
41
|
|
|
* @var string The public URL to use when not using the dev server |
|
42
|
|
|
*/ |
|
43
|
|
|
public string $serverPublic = ''; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
|
|
|
|
|
46
|
|
|
* @var string|array The JavaScript entry from the manifest.json to inject on Twig error pages |
|
47
|
|
|
* This can be a string or an array of strings |
|
48
|
|
|
*/ |
|
49
|
|
|
public string|array $errorEntry = ''; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
|
|
|
|
|
52
|
|
|
* @var string String to be appended to the cache key |
|
53
|
|
|
*/ |
|
54
|
|
|
public string $cacheKeySuffix = ''; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
|
|
|
|
|
57
|
|
|
* @var string The internal URL to the dev server, when accessed from the environment in which PHP is executing |
|
58
|
|
|
* This can be the same as `$devServerPublic`, but may be different in containerized or VM setups. |
|
59
|
|
|
* ONLY used if $checkDevServer = true |
|
60
|
|
|
*/ |
|
61
|
|
|
public string $devServerInternal = ''; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
|
|
|
|
|
64
|
|
|
* @var bool Should we check for the presence of the dev server by pinging $devServerInternal to make sure it's running? |
|
65
|
|
|
*/ |
|
66
|
|
|
public bool $checkDevServer = false; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
|
|
|
|
|
69
|
|
|
* @var bool Whether the react-refresh-shim should be included |
|
70
|
|
|
*/ |
|
71
|
|
|
public bool $includeReactRefreshShim = false; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
|
|
|
|
|
74
|
|
|
* @var bool Whether the modulepreload-polyfill shim should be included |
|
75
|
|
|
*/ |
|
76
|
|
|
public bool $includeModulePreloadShim = true; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
|
|
|
|
|
79
|
|
|
* @var string File system path (or URL) to where the Critical CSS files are stored |
|
80
|
|
|
*/ |
|
81
|
|
|
public string $criticalPath = ''; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
|
|
|
|
|
84
|
|
|
* @var string the suffix added to the name of the currently rendering template for the critical css file name |
|
85
|
|
|
*/ |
|
86
|
|
|
public string $criticalSuffix = '_critical.min.css'; |
|
87
|
|
|
|
|
88
|
|
|
// Public Methods |
|
89
|
|
|
// ========================================================================= |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
|
|
|
|
|
92
|
|
|
* @inheritdoc |
|
93
|
|
|
*/ |
|
|
|
|
|
|
94
|
|
|
public function rules(): array |
|
95
|
|
|
{ |
|
96
|
|
|
return [ |
|
97
|
|
|
[ |
|
98
|
|
|
[ |
|
99
|
|
|
'useDevServer', |
|
100
|
|
|
'checkDevServer', |
|
101
|
|
|
'includeReactRefreshShim', |
|
102
|
|
|
'includeModulePreloadShim', |
|
103
|
|
|
], |
|
104
|
|
|
'boolean', |
|
105
|
|
|
], |
|
106
|
|
|
[ |
|
107
|
|
|
[ |
|
108
|
|
|
'manifestPath', |
|
109
|
|
|
'devServerPublic', |
|
110
|
|
|
'serverPublic', |
|
111
|
|
|
'cacheKeySuffix', |
|
112
|
|
|
'devServerInternal', |
|
113
|
|
|
], |
|
114
|
|
|
'string', |
|
115
|
|
|
], |
|
116
|
|
|
[ |
|
117
|
|
|
[ |
|
118
|
|
|
'errorEntry', |
|
119
|
|
|
], |
|
120
|
|
|
'string', |
|
121
|
|
|
], |
|
122
|
|
|
]; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|