【问题标题】:Can I set a single .NET MVC bundle to always be bundled (even in debug mode)?我可以将单个 .NET MVC 捆绑包设置为始终捆绑(即使在调试模式下)?
【发布时间】:2014-09-30 19:56:45
【问题描述】:

我在我的文件中使用 .LESS 变量。我的 Bundler 中有一个 LessTransform,它允许我所有的 .less 看到变量。但是当我关闭捆绑时,显然它不再起作用了!

我可以只看到一个捆绑包吗? (即使编译调试=true)

【问题讨论】:

    标签: asp.net-mvc less bundling-and-minification


    【解决方案1】:

    不幸的是,这是一个全有或全无的设置(由 AssetManager.DeterminePathsToRender 很早就确定,基于 EnableOptimizations,要么发出捆绑 URL,要么发出单独的脚本路径)。

    您可以考虑使用 WebEssentials 扩展,它可以原生处理 .less(以及其他)文件。至少那时您将能够包含已编译的版本并让您处理更重要的事情。完成后,您可以重新考虑捆绑。

    我不为 WebEssentials 工作,我只是觉得这个扩展很有帮助

    【讨论】:

      【解决方案2】:

      在我使用的主应用程序中,我们直接使用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")));
         }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-30
        • 2012-10-28
        • 2013-05-25
        • 2012-11-30
        • 1970-01-01
        • 2012-08-10
        • 2012-09-19
        • 2016-04-15
        相关资源
        最近更新 更多