Skip to content

Commit

Permalink
Dont optimize with URL
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysm committed Jan 7, 2024
1 parent 40ab28b commit 9c32af2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Commands/OptimizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function handle(Importmap $importmap): int
->map(function (string $oldFilename, string $module) use ($preloadModulePaths, $optimizedImports) {
return [
'module' => $module,
'path' => isset($optimizedImports[$module]) ? asset($optimizedImports[$module]) : $oldFilename,
'path' => $optimizedImports[$module] ?? $oldFilename,
'preload' => in_array($oldFilename, $preloadModulePaths),
];
})
Expand Down
12 changes: 6 additions & 6 deletions src/Importmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function pinAllFrom(string $dir, ?string $under = null, ?string $to = nul
public function preloadedModulePaths(callable $assetResolver): array
{
if ($this->hasManifest()) {
return $this->resolvePreloadedModulesFromManifest();
return $this->resolvePreloadedModulesFromManifest($assetResolver);
}

return $this->resolveAssetPaths($this->expandPreloadingPackagesAndDirectories(), $assetResolver);
Expand All @@ -42,7 +42,7 @@ public function preloadedModulePaths(callable $assetResolver): array
public function asArray(callable $assetResolver): array
{
if ($this->hasManifest()) {
return $this->resolveImportsFromManifest();
return $this->resolveImportsFromManifest($assetResolver);
}

return [
Expand Down Expand Up @@ -70,19 +70,19 @@ private function manifestPath(): string
return Manifest::path();
}

private function resolvePreloadedModulesFromManifest(): array
private function resolvePreloadedModulesFromManifest($assetResolver): array
{
return collect(json_decode(File::get($this->manifestPath()), true))
->filter(fn (array $json) => $json['preload'])
->mapWithKeys(fn (array $json) => [$json['module'] => $json['path']])
->mapWithKeys(fn (array $json) => [$json['module'] => $assetResolver($json['path'])])
->all();
}

private function resolveImportsFromManifest(): array
private function resolveImportsFromManifest($assetResolver): array
{
return [
'imports' => collect(json_decode(File::get($this->manifestPath()), true))
->mapWithKeys(fn (array $json) => [$json['module'] => $json['path']])
->mapWithKeys(fn (array $json) => [$json['module'] => $assetResolver($json['path'])])
->all(),
];
}
Expand Down

0 comments on commit 9c32af2

Please sign in to comment.