Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load the files listed in chunk.imports on production mode #20

Open
wants to merge 1 commit into
base: cake5
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/View/Helper/ViteScriptsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,33 @@ private function productionScript(array $options, ViteHelperConfig $config): voi
$pluginPrefix = $config->read('plugin');
$pluginPrefix = $pluginPrefix ? $pluginPrefix . '.' : null;

$records = $this->getFilteredRecords(ViteManifest::getRecords($config), $options);
$manifestRecords = ViteManifest::getRecords($config);

$entryRecords = $this->getFilteredRecords($manifestRecords, $options);
// check chunk.imports
$shouldImports = $entryRecords->reduce(
static function (array $carry, ManifestRecord $record) {
$imports = $record->getChunk('imports') ?? [];

return array_merge($carry, $imports);
},
[]
);
// add chunk.imports files to prodFilter
if (is_array($options['prodFilter'])) {
$options['prodFilter'] = array_merge($options['prodFilter'], $shouldImports);
}

$manifestRecords->rewind();
$records = $this->getFilteredRecords($manifestRecords, $options);
$cssBlock = $options['cssBlock'];
unset($options['prodFilter']);
unset($options['cssBlock']);
unset($options['devEntries']);

foreach ($records as $record) {
if (!$record->isEntryScript()) {
/** @var \ViteHelper\Utilities\ManifestRecord $record */
if (!$record->isEntryScript() && !in_array($record->getKey(), $shouldImports, true)) {
continue;
}

Expand Down Expand Up @@ -333,7 +352,7 @@ private function getFilteredRecords(ManifestRecords $records, array $options): M
return $records->filter(function (ManifestRecord $record) use ($filter) {
foreach ($filter as $property => $file) {
$property = is_string($property) ? $property : 'src';
if ($record->match($file, $property)) {
if ($record->match($file, $property) || $record->getKey() === $file) {
return true;
}
}
Expand Down
Loading