Skip to content

Instantly share code, notes, and snippets.

@timkelty
Last active May 7, 2021 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timkelty/57810962cfb8f66126168eb6daf5a310 to your computer and use it in GitHub Desktop.
Save timkelty/57810962cfb8f66126168eb6daf5a310 to your computer and use it in GitHub Desktop.
<?php
function extractCssFiles(array $manifest, string $manifestKey): array
{
$entry = $manifest[$manifestKey] ?? null;
if (!$entry) {
return [];
}
$cssFiles = array_values($entry['css'] ?? []);
$imports = array_merge($entry['imports'] ?? [], $entry['dynamicImports'] ?? []);
$importFiles = array_map(function ($manifestKey) use ($manifest, $manifestKey) {
return $this->extractCssFiles($manifest, $manifestKey);
}, $imports);
array_push($cssFiles, ...$importFiles);
return array_unique($cssFiles);
}
<?php
function extractCssFiles(array $manifest, string $manifestKey): array
{
$entry = $manifest[$manifestKey] ?? null;
if (!$entry) {
return [];
}
$cssFiles = array_values($entry['css'] ?? []);
$imports = array_merge($entry['imports'] ?? [], $entry['dynamicImports'] ?? []);
return array_reduce($imports, function ($cssFiles, $manifestKey) use ($manifest) {
return array_unique(array_merge($cssFiles, $this->extractCssFiles($manifest, $manifestKey)));
}, $cssFiles);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment