5
bundles.Add(new StyleBundle("~/a/b/c")
    .Include("~/Content/font-awesome.css", new CssRewriteUrlTransform()));

I have this bundling. The font-awesome css has a url defined as url('../fonts/fontawesome-webfont.eot?v=4.0.3') which is valid when the css is located under "~/Content/font-awesome.css" but now its located under "~/a/b"

But CssRewriteUrlTransform does not kick in and rewrite path to url('../../fonts/fontawesome-webfont.eot?v=4.0.3')

Update: If I remove the .min file it CssRewriteUrlTransformstarts to work, bug in web optimization?

https://aspnetoptimization.codeplex.com/workitem/166

Anders
  • 17,306
  • 10
  • 76
  • 144
  • 1
    Deleting the min css file worked for me, thanks for the 'Update'. I think the bundling tries to skip the minification process if it finds a static min- which bypasses the CssRewriteUrlTransform, does seem like a bug but easy to work around. – stlawrence Nov 08 '17 at 15:47
  • Does seem like an unwise attempt by MS to "optimize" bundling, which leads to hard to debug issue. – vkelman Dec 07 '20 at 16:56

1 Answers1

3

Had the same problem with me.

You need to set the Bundle url relative to the folder of your file.

bundles.Add(new StyleBundle("~/Content/fontawesomebundle")
    .Include("~/Content/font-awesome.css", new CssRewriteUrlTransform()));

Update: It appears that CssRewriteUrlTransform doesn't work for min file. Either use .min file in the include or remove the min file.

Ruchan
  • 3,124
  • 7
  • 36
  • 72
  • 1
    But then you can ass well remove the CssRewriteUrlTransform since it does nothing – Anders May 25 '15 at 09:42
  • Are you testing in a hosted site (with virtual directory) or in development? – Ruchan May 25 '15 at 10:23
  • 6
    the bundle by default will use .min file if it exists. that might be the case – Ruchan May 27 '15 at 06:24
  • 1
    But the transform should be used for min files too – Anders May 27 '15 at 12:06
  • 3
    Turns out min file is used even though it's not included, and that no transform is done when min i used. I had to remove a file that shouldn't be in use to make things work. Nice thinking Microsoft. – Malako Jul 18 '16 at 14:37
  • Thank you @Ruchan! Does seem like an unwise attempt by MS to "optimize" bundling, which leads to hard to debug issue. – vkelman Dec 07 '20 at 16:57