diff --git a/src/Commands/OptimizeCommand.php b/src/Commands/OptimizeCommand.php index 192bf94..1b1fe06 100644 --- a/src/Commands/OptimizeCommand.php +++ b/src/Commands/OptimizeCommand.php @@ -24,7 +24,7 @@ public function handle(Importmap $importmap): int $optimizedImports = collect($imports['imports']) ->reject(fn (string $url) => Str::startsWith($url, ['http://', 'https://'])) ->map(function (string $file) use ($importmap) { - $sourceFile = $importmap->rootPath.(str_starts_with($file, 'vendor/') ? '/public/' : '/resources/').trim($file, '/'); + $sourceFile = $importmap->rootPath.(str_starts_with(trim($file, '/'), 'vendor/') ? '/public/' : '/resources/').trim($file, '/'); $sourceReplacement = $importmap->rootPath.'/public/dist/'.trim($this->digest($file, $sourceFile), '/'); File::ensureDirectoryExists(dirname($sourceReplacement)); diff --git a/tests/OptimizeCommandTest.php b/tests/OptimizeCommandTest.php index 183a830..805a5ba 100644 --- a/tests/OptimizeCommandTest.php +++ b/tests/OptimizeCommandTest.php @@ -22,6 +22,7 @@ protected function setUp(): void $this->map->pin('app'); $this->map->pin('md5', to: 'https://cdn.skypack.dev/md5', preload: true); $this->map->pin('my_lib', to: 'vendor/nova/my_lib.js', preload: true); + $this->map->pin('my_other_lib', to: '/vendor/nova/my_other_lib.js', preload: true); if (File::isDirectory($this->distPath = $this->rootPath.'/public/dist/')) { File::cleanDirectory($this->distPath); diff --git a/tests/stubs/public/vendor/nova/my_other_lib.js b/tests/stubs/public/vendor/nova/my_other_lib.js new file mode 100644 index 0000000..e69de29