williamsandonz
williamsandonz

Reputation: 16430

Can I set a single .NET MVC bundle to always be bundled (even in debug mode)?

I am using .LESS variables in my files. I have a LessTransform in my Bundler, which allows all my .less to see the variables. But when I turn bundling off, obviously it no longer works!

Can I see just a single bundle to always be bundled? (even when compilation debug=true)

Upvotes: 0

Views: 73

Answers (2)

Jeremy Bell
Jeremy Bell

Reputation: 718

In the main application that I work with, we use the DotLess compiler directly to serve our stylesheets.

We store custom .LESS variables in the database and combine them with the .less file on the fly.

using System.Web.Mvc;

using dotless.Core;

using System.Web.Helpers;

public class SkinController : Controller
{
   private const int TwentyMinutes = 1200;

   [OutputCache(Duration = TwentyMinutes, VaryByParam = "*", VaryByContentEncoding = "gzip;deflate", VaryByCustom = "Scheme")]
   public ActionResult Index()
   {
       string variablesFromDatabase = "these came from the database";

       string lessFileContents = "this was read from the disk";

       string content = Less.Parse(string.Concat(variablesFromDatabase, lessFileContents));

       SetEtag(content);

       return Content(content, "text/css");
   }

   private void SetEtag(string content)
   {
       string acceptEncoding = Request.Headers["Accept-Encoding"];

       string value = string.Concat(content, acceptEncoding);

       Response.AppendHeader("etag", string.Format("\"{0}\"", Crypto.Hash(value, "md5")));
   }
}

Upvotes: 0

Brad Christie
Brad Christie

Reputation: 101614

Unfortunately it's an all or nothing setup (determined very early on by AssetManager.DeterminePathsToRender which, based on EnableOptimizations, either emits a bundle URL or individual script paths).

You could look into using the WebEssentials extension which handles .less (as well as other) files natively. At least then you'll be able to include the compiled version and let you move onto more important matters. Once you've finalized, you can bring bundling back into the equation.

I do not work on/for WebEssentials, I just find the extension very helpful

Upvotes: 1

Related Questions