diff --git a/src/CSS.php b/src/CSS.php index 89fcf1b..bcbc377 100644 --- a/src/CSS.php +++ b/src/CSS.php @@ -262,7 +262,7 @@ protected function importFiles($source, $content) // get the path for the file that will be imported $path = $match[2]; - $path = dirname($source).'/'.$path; + $path = $this->resourcesBasePath . dirname($source).'/'.$path; // only replace the import with the content if we're able to get // the content of the file, and it's relatively small diff --git a/src/Minify.php b/src/Minify.php index 3f40bc1..895fb27 100644 --- a/src/Minify.php +++ b/src/Minify.php @@ -48,6 +48,15 @@ abstract class Minify */ public $extracted = array(); + /** + * Path from where resources like images, fonts etc. can be imported. + * Minify will be default look for resources based on its path defined in CSS, + * if your structure of files is different because of different folder structure, + * you can specify base directory. + * @var string + */ + protected $resourcesBasePath = ""; + /** * Init the minify class - optionally, code may be passed along already. */ @@ -105,7 +114,7 @@ public function add($data /* $data = null, ... */) * @param string|string[] $data * * @return static - * + * * @throws IOException */ public function addFile($data /* $data = null, ... */) @@ -192,6 +201,18 @@ public function cache(CacheItemInterface $item) return $item; } + /** + * Path from where resources like images, fonts etc. can be imported. + * Minify will be default look for resources based on its path defined in CSS, + * if your structure of files is different because of different folder structure, + * you can specify base directory. + * @var string + */ + public function setResourcesBasePath(string $path) + { + $this->resourcesBasePath = $path; + } + /** * Minify the data. *