CssRewriteUrlTransform does not take
Asked Answered
S

1

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

Seldom answered 25/5, 2015 at 9:14 Comment(2)
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.Huber
Does seem like an unwise attempt by MS to "optimize" bundling, which leads to hard to debug issue.Pasty
G
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.

Gunyah answered 25/5, 2015 at 9:36 Comment(6)
But then you can ass well remove the CssRewriteUrlTransform since it does nothingSeldom
Are you testing in a hosted site (with virtual directory) or in development?Gunyah
the bundle by default will use .min file if it exists. that might be the caseGunyah
But the transform should be used for min files tooSeldom
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.Carbarn
Thank you @Ruchan! Does seem like an unwise attempt by MS to "optimize" bundling, which leads to hard to debug issue.Pasty

© 2022 - 2024 — McMap. All rights reserved.