perf: Optimized Vite entrypoints

This commit is contained in:
Maicol Battistini 2022-03-02 13:50:10 +01:00
parent dffce3c724
commit 1f0d746771
No known key found for this signature in database
GPG Key ID: 4FDB0F87CDB1D34A
1 changed files with 6 additions and 31 deletions

View File

@ -1,35 +1,5 @@
<?php
/**
* List all the directories under a directory.
*
* @param string $dir Parent directory
* @param false $include_parent Include parent directory in the returned array
* @param bool $relative Use relative paths instead of absolute ones
* @source https://www.php.net/manual/en/function.glob.php#82182
*/
if (!function_exists('listdirs')) {
function listdirs(string $dir, bool $include_parent = false, bool $relative = true): array
{
$dirs = $include_parent ? [$dir] : [];
$next = 0;
while (true) {
$glob = glob($dir.'/*', GLOB_ONLYDIR);
if (count($glob) > 0) {
$dirs = [...$dirs, ...array_values($glob)];
} else {
break;
}
$dir = $dirs[$next++];
}
return $relative ? array_unique(array_map(static fn ($dir) => ltrim(str_replace(base_path(), '', $dir), DIRECTORY_SEPARATOR), $dirs)) : $dirs;
}
}
return [
/*
|--------------------------------------------------------------------------
@ -39,7 +9,12 @@ return [
| entry points and will not be required in the configuration file.
| To disable the feature, set to false.
*/
'entrypoints' => listdirs(resource_path('js'), true),
'entrypoints' => [
resource_path('js/index.ts'),
resource_path('js/styles.ts'),
resource_path('js/_material.ts'),
resource_path('js/app.ts')
],
'ignore_patterns' => ['/\\.d\\.ts$/'],
/*