Skip to content

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

Open
schmunk42 wants to merge 4 commits intomikehaertl:masterfrom
schmunk42:feature-copy-css-images
Open

added optional feature for rewriting CSS images to output-fol...#6
schmunk42 wants to merge 4 commits intomikehaertl:masterfrom
schmunk42:feature-copy-css-images

Conversation

@schmunk42
Copy link
Contributor

...der on package compression.

Experimental! See also yiisoft/yii#1033 - how do you work around the images problem?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to copyCssAssets. I'd also change the docs to:

Whether to copy CSS assets from their source location to the package output directory. Note, that this
feature is considered experimental. It will copy all files from the CSS files' source directory to the
package output directory which may not always lead to useful results.

@schmunk42
Copy link
Contributor Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants