Skip to content

Instantly share code, notes, and snippets.

@yngvebn
Created January 10, 2014 06:31
Show Gist options
  • Save yngvebn/8347809 to your computer and use it in GitHub Desktop.
Save yngvebn/8347809 to your computer and use it in GitHub Desktop.
Workaround for invalid Media Query minification (WebGrease and System.Web.Optimization)
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
var siteCssBundle = new StyleBundle("~/css/site").IncludeDirectory("~/public/css", "*.css");
siteCssBundle.Transforms.Clear();
siteCssBundle.Transforms.Add(new CustomCssMinify());
bundles.Add(siteCssBundle);
}
}
public class CustomCssMinify : CssMinify
{
public override void Process(BundleContext context, BundleResponse response)
{
// Workaround for a bug in WebGrease/System.Web.Optimization
// missing leading whitespace before 'and', 'not', 'only'
// hopefully a fix will come!
base.Process(context, response);
response.Content = response.Content
.Replace(")and ", ") and ")
.Replace(")not ", ") not ")
.Replace(")only ", ") only ");
}
}
@ctolkien
Copy link

I would assume that this is only called once when changes are detected?

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