【问题标题】:dotlesscss does not show errorsdotlesscss 不显示错误
【发布时间】:2013-09-03 00:12:58
【问题描述】:

我的 css 有问题,因为编译后没有样式添加到我的网站。

如何让 dotlesscss 显示错误?常规的 .less 向您显示一条非常方便的好消息。

【问题讨论】:

    标签: dotless


    【解决方案1】:

    您可以使用 web.config 轻松完成此操作。在无点配置部分中,添加以下内容:logger="dotless.Core.Loggers.AspResponseLogger"。这将使无点输出错误而不是空白 css。

    我已将以下内容作为示例。 (“...”代表 web.config 中的现有内容)。在我下面的示例中,缓存设置为 false。这对于调试目的很有用。正常情况下应该设置为true。

    <configuration>    
         <configSections>
               ...
              <section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler,dotless.Core" />
          </configSections>
    
          <dotless minifyCss="false" cache="false" 
                logger="dotless.Core.Loggers.AspResponseLogger" />
           ...    
    </configuration>    
    

    【讨论】:

    • 这并不总是有效。即使 Less.js 有效,我仍然得到一个空白的 css。我正在使用捆绑和缩小。
    • 这似乎对我也不起作用 - 有些文件有错误,有些是空白的,有些在 Chrome 的网络视图中是红色的(状态:已取消)。
    【解决方案2】:

    我今天刚刚在我的RequestReduce 项目中遇到了这个问题。我得到了更少的空白 - > css 转换,因为似乎有解析错误进入以太。谢谢 这个相关的答案How can I output errors when using .less programmatically? 我能够找到一个解决方案,我可以将错误写入响应流。您必须创建一个从 dotless.Core.Loggers.ILogger 派生的 Logger:

    public class LessLogger : ILogger
    {
        public void Log(LogLevel level, string message)
        {
        }
    
        public void Info(string message)
        {
        }
    
        public void Debug(string message)
        {
        }
    
        public void Warn(string message)
        {
        }
    
        public void Error(string message)
        {
            Response.Write(message);
        }
    
        public HttpResponseBase Response { get; set; }
    }
    

    您将其传递到发送到 EngineFactory 的配置中:

                var engine = new EngineFactory(new DotlessConfiguration
                                                   {
                                                       CacheEnabled = false,
                                                       Logger = typeof (LessLogger)
                                                   }
                    ).GetEngine();
    

    出于单元测试的目的,我想传入会写入错误的 HttpResponseBase。这就是我觉得通过一些讨厌的转换来获取对我的记录器的引用变得丑陋的地方:

                ((LessLogger)((LessEngine)((ParameterDecorator)engine).Underlying).Logger).Response = response;
    

    希望对你有所帮助。

    【讨论】:

      猜你喜欢
      • 2014-04-02
      • 2012-03-09
      • 2011-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-14
      相关资源
      最近更新 更多