packagecompressor icon indicating copy to clipboard operation
packagecompressor copied to clipboard

added optional feature for rewriting CSS images to output-fol...

Open schmunk42 opened this issue 12 years ago • 1 comments

...der on package compression.

Experimental! See also https://github.com/yiisoft/yii/issues/1033 - how do you work around the images problem?

schmunk42 avatar Oct 10 '13 03:10 schmunk42

I found a much better solution, IMHO. Please let me know what you think.

tl;dr Basically don't copy anything, but (optionally) rewrite CSS file URLs relative to your webroot.

PackageCompressor ~line 149

            foreach(array_keys($this->cssFiles) as $file) {
                $f = $basePath.$file;
                if ($this->rewriteCssUris) {
                    file_put_contents($f, Minify_CSS_UriRewriter::rewrite(file_get_contents($f), dirname($f), $basePath));
                }
                $files[] = $f;
            }

This would replace the previous PR.

Background: I ran into issue with YiiBooster, which contains relative URLs with ../fonts. The current proposal is unable to catch these cases and moreover the files are all already available in a public location. So I seemed the most natural solution to me to reuse these files in the final CSS.

Works fine so far from a virtual host, I had an issue with running it from a sub-path, but that should be fixable.

PS: This would also add one composer dependency.

[edit] sample output: url(/assets/7dd6006e/img/ui-bg_glass_75_ffffff_1x400.png)

schmunk42 avatar Oct 13 '13 14:10 schmunk42