Postcss 语法错误

Postcss Syntax Errors silently

所以我目前正在建立一个项目,只使用 postcss 并完全放弃 scss。我正在努力解决的一件事是,如果出现语法错误,则不会报告任何错误。

例如,我添加了 precss 插件,当我拼写错误的变量时:

$somevar: #000;
.body{
  color:$oopsvar;
}

显然在 SCSS 中它会抛出错误并告诉我 $oopsvar 不存在。但它只是解析它 returns:

.body{
  color:$oopsvar;
}

这显然是无效的。我添加了 postcss-reporter、postcss-devtools,甚至尝试查看 stylelint 中是否有任何可能显示错误的规则,但没有。

现在我不确定这是否只是像 precss 这样的插件的问题,或者我在 postcss 中缺少的整体问题。别人怎么调试postcss,还是只看浏览器?

如果你想找到所有的错误,你应该使用 linter。 Stylelint 将是不错的选择(基于PostCSS)。

PostCSS 用于许多 CSS 工具。其中一些工具使用自定义语法。这就是为什么 PostCSS 可以解析自定义语法($somevar: #000; 被解析为 $somevar 属性)。

所以我做了一些调查并在 postcss gitter

上聊天

有一种显示 warnings and errors in postcss, however due to the plugin approach it up to the individual plugin creators to implement. The issue I had with precss which isn't being maintained so was the issue that they weren't displaying any warning. We've moved more towards cssnext 的内置方式得到了很好的维护,尽管语法略有不同,因为它使用建议的 css 变量而不是 scss 语法。

如果已实施,您还需要 postcss-reporter 来获取警告和错误。