3

I got the old Would you like to normalize line endings on my .less file and without thinking did so.

I realized later that my css wasnt completely minified. Here's the process method for the transform

public void Process(BundleContext context, BundleResponse response)
{
    response.Content = dotless.Core.Less.Parse(response.Content);
    response.ContentType = "text/css";
}

BundleConfig.cs

bundles.Add(new Bundle("~/Less/css", new LessTransform(), new CssMinify())
    .Include("~/Content/css/App.less"));

I put a break point in Process and copied the before/after CSS and found that dotless was only removing /r and not /n

Here's a snippet of my css file showing the behavior

Before dotless Parse

"/*\r\n\r\nApp.less\r\n

After dotless Parse

"/*\n\nApp.less\n

So it's technically working, just not optimally. I was thinking about going back and removing the /r/n from the file and replacing them with just /r but would love a solution that doesn't cause the line endings dialog to pester me whenever I open the file.

UPDATE: Forgot that I upgraded the dotless nuget package recently as well

My Webconfig

<configSections>
    <section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" />
    ...
</configSections>
...
<httpHandlers>
  <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
</httpHandlers>
...
<handlers>
     <add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
</handlers>
...
<dotless minifyCss="true" />
Community
  • 1
  • 1
jamesSampica
  • 12,230
  • 3
  • 63
  • 85

1 Answers1

1

Here is an example that gives me a properly minified result, very similar to what you currently have:

BundleConfig

BundleTable.EnableOptimizations = true; // I think is what's missing

var cssBundle = new StyleBundle("~/Content/css")
    .Include("~/Content/site.less");

cssBundle.Transforms.Add(new LessTransform());
cssBundle.Transforms.Add(new CssMinify());

bundles.Add(cssBundle);

LessTransform

public void Process(BundleContext context, BundleResponse response)
{
    response.Content = dotless.Core.Less.Parse(response.Content);
    response.ContentType = "text/css";
}

With no Web.config sections.

Bensmind
  • 169
  • 1
  • 7
  • You can see in my question that my file *was* being minified. The characters being excluded from minification were carriage returns. – jamesSampica Jan 07 '15 at 04:45
  • Right, the above code collapses bot \n and \r for me. – Bensmind Jan 07 '15 at 05:42
  • My suggestion would be to remove all the Web.config sections as you shouldn't need both the LessTransform and the dotless handler; change your bundle to a StyleBundle, the LessTransform will handle the transform itself and CssMinify handle the standard minification. – Bensmind Jan 07 '15 at 05:49