Skip to content

Commit 61d7dd5

Browse files
author
arnoson
committed
chore: minor changes
1 parent bfb6556 commit 61d7dd5

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

packages/kirby-vite/Vite.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Vite {
1212
protected bool $hasLegacyPolyfills = false;
1313
protected ?bool $isDev = null;
1414
protected ?string $outDir = null;
15+
protected ?string $server = null;
1516
protected ?array $manifest = null;
1617
protected ?array $config = null;
1718

@@ -55,7 +56,7 @@ protected function config(): array {
5556
}
5657

5758
/**
58-
* Get Vite's `outDir`, but relative to Kirby's index root.
59+
* Get Vite's `outDir` relative to Kirby's index root.
5960
*/
6061
protected function outDir(): string {
6162
return $this->outDir ??= kirby()->root('base')
@@ -76,6 +77,10 @@ protected function baseDir(): string {
7677
* @throws Exception
7778
*/
7879
protected function server(): string {
80+
if (isset($server)) {
81+
return $server;
82+
}
83+
7984
$devDir = kirby()->root('base') ?? kirby()->root('index');
8085
$dev = F::read("$devDir/.dev");
8186

@@ -84,7 +89,7 @@ protected function server(): string {
8489
throw new Exception('VITE_SERVER not found in `.dev` file.');
8590
}
8691

87-
return $value;
92+
return $this->server = $value;
8893
}
8994

9095
/**
@@ -145,19 +150,12 @@ protected function client(): ?string {
145150
return js($this->assetDev('@vite/client'), ['type' => 'module']);
146151
}
147152

148-
/**
149-
* Get the url for the specified file for development mode.
150-
*/
151153
protected function assetDev(string $file): string {
152154
return $this->server() . "/$file";
153155
}
154156

155-
/**
156-
* Get the URL for the specified file for production mode.
157-
*/
158157
protected function assetProd(string $file): string {
159-
$outDir = $this->outDir();
160-
return "/$outDir/$file";
158+
return '/' . $this->outDir() . "/$file";
161159
}
162160

163161
/**
@@ -211,9 +209,9 @@ public function js(
211209
}
212210

213211
/**
214-
* Include the css file for the specified entry in production mode. Your CSS
215-
* file can either be CSS entry `vite()->css('main.css')` or a js entry
216-
* `vite()->css('main.js')`, in this case the CSS imported in the JS file will
212+
* Include the css file for the specified entry in production mode. Your css
213+
* file can either be css entry `vite()->css('main.css')` or a js entry
214+
* `vite()->css('main.js')`, in this case the css imported in the js file will
217215
* be used.
218216
*/
219217
public function css(

0 commit comments

Comments
 (0)