2014-09-30 51 views

回答

1

不幸的是,它是一個全部或全無的設置(早在AssetManager.DeterminePathsToRender確定,其基於EnableOptimizations,或者發出一個包URL或單個腳本路徑)。

你可以使用WebEssentials擴展名,它本身處理.less(以及其他)文件。至少你可以包含編譯後的版本,並讓你進入更重要的事情。一旦你完成了,你可以把這個捆綁回來。

我不工作的/爲WebEssentials,我只要找到擴展很有幫助

0

在我工作的主要應用,我們使用DotLess編譯直接服務於我們的樣式表。

我們將自定義的.LESS變量存儲在數據庫中,並將它們與.less文件實時組合。

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"))); 
    } 
}