0

In a css file i have this:

.social-icons li .facebook {
  background: url(../img/social/facebook.png) no-repeat;
}

The img directory is indeed in "../" compared to the css file.

Everything works ok if i include the css with normal markup in my _Layout.cshtml.

But if i use bundling:

bundles.Add(new StyleBundle("~/bundles/core-styles").Include(
        "~/assets/global/frontend/css/components.css"));

it breaks all images.

Is there any way to use bundling AND have correct images without of course touching the components.css?

e4rthdog
  • 5,103
  • 4
  • 40
  • 89

1 Answers1

1

You can use CssRewriteUrlTransform when including the bundle:

bundles.Add(new StyleBundle("~/bundles/core-styles")
    .Include("~/assets/global/frontend/css/components.css", new CssRewriteUrlTransform()));

That class rewrites the URLs in the file to be absolute and it will fix your problem.

Omri Aharon
  • 16,959
  • 5
  • 40
  • 58