drdk / grunt-dr-svg-sprites

Grunt plugin to create SVG sprites with PNG fallbacks at needed sizes
113 stars 19 forks source link

Custom Css background-image URL in output #47

Closed dutchwebworks closed 9 years ago

dutchwebworks commented 9 years ago

I'm trying to change the final Css background-image URL path in the output to a custom root relative path.

Currently it's relative to the Css file:

.no-svg .sprite-main-image-01, .no-svg .sprite-main-image-02 {
    background-image: url("../img/sprites/main-sprite.png");
}

.svg .sprite-main-image-01, .svg .sprite-main-image-02 {
    background-image: url("../img/sprites/main-sprite.svg");
}

But I want to customize it to a root relative path (or maybe even a hardcoded CDN like URL):

.no-svg .sprite-main-image-01, .no-svg .sprite-main-image-02 {
    background-image: url("/themes/main/img/sprites/main-sprite.png");
}

.svg .sprite-main-image-01, .svg .sprite-main-image-02 {
    background-image: url("/themes/main/img/sprites/main-sprite.svg");
}

Because our backend code minifies, bundles and then serves the Css file from a different URL so the relative path does not resolve.

I've tried fiddling with a custom Handlebar template:

background-image: url("{{url ../svgPath ../cssPath}}");

But I can't seem to change the url helper nor the two arguments. When changing the two argument somehow generates a very long unwanted local filesystem path.

phloe commented 9 years ago

dr-svg-sprites was designed to build a set of assets with relative paths. If you want to change the paths you should probably be doing it via a separate buildstep.

phloe commented 9 years ago

Closing this as it is outside the scope of what the plugin should be doing. I this sound reasonable :)