我在我的文件中使用了.LESS變量。我在Bundler中有一個LessTransform,它允許我所有的無人看到變量。但是當我打開包裝時,顯然它不再有效!我可以將單個.NET MVC捆綁包設置爲始終捆綁(即使在調試模式下)嗎?
我可以看到只有一個捆綁包總是捆綁在一起嗎? (即使編譯debug = true)
我在我的文件中使用了.LESS變量。我在Bundler中有一個LessTransform,它允許我所有的無人看到變量。但是當我打開包裝時,顯然它不再有效!我可以將單個.NET MVC捆綁包設置爲始終捆綁(即使在調試模式下)嗎?
我可以看到只有一個捆綁包總是捆綁在一起嗎? (即使編譯debug = true)
不幸的是,它是一個全部或全無的設置(早在AssetManager.DeterminePathsToRender
確定,其基於EnableOptimizations
,或者發出一個包URL或單個腳本路徑)。
你可以使用WebEssentials擴展名,它本身處理.less
(以及其他)文件。至少你可以包含編譯後的版本,並讓你進入更重要的事情。一旦你完成了,你可以把這個捆綁回來。
我不工作的/爲WebEssentials,我只要找到擴展很有幫助
在我工作的主要應用,我們使用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")));
}
}