dotlesscss 不显示错误

发布于 2024-12-11 07:07:59 字数 89 浏览 0 评论 0原文

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

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

There's something wrong with my css because no styles are being added to my website after compilation.

How do I get dotlesscss to show errors? Regular .less shows you a nice message that's very handy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆梦 2024-12-18 07:07:59

您可以使用 web.config 轻松完成此操作。在 dotless 配置部分中,添加以下内容: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>    

You can do this very easily with web.config. In your dotless configuration section, add the following: logger="dotless.Core.Loggers.AspResponseLogger". This will make dotless output the errors instead of blank css.

I've included the following as an example. ("..." represents existing stuff in your web.config). In my example below cache is set to false. This is useful for debugging purposes. It should probably be set to true under normal circumstances.

<configuration>    
     <configSections>
           ...
          <section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler,dotless.Core" />
      </configSections>

      <dotless minifyCss="false" cache="false" 
            logger="dotless.Core.Loggers.AspResponseLogger" />
       ...    
</configuration>    
太傻旳人生 2024-12-18 07:07:59

我今天刚刚在我的 RequestReduce 项目中遇到了这个问题。我变得越来越空白 -> css 转换是因为存在解析错误,这些错误似乎正在进入以太坊。由于
此相关答案 以编程方式使用 .less 时如何输出错误? 我能够找到一个解决方案,可以将错误写入响应流。您必须创建一个从 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;

我希望这可以帮助你。

I just faced this today in my RequestReduce project. I was getting blank less -> css transforms because there were parse errors that appeared to be going into the ether. Thanks to
this related answer How can I output errors when using .less programmatically? I was able to work out a solution where I could write the errors to the response stream. You have to create a Logger derriving from dotless.Core.Loggers.ILogger:

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

You pass this into the Configuration sent to the EngineFactory:

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

For unit testing purposes I wanted to pass in my HttpResponseBase that would write the error. This is where I felt things getting ugly with some nasty casting to get a reference to my logger:

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

I hope this helps you out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文