我在我的文件中使用了.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")));
}
}