symfony - Stylelint 输出不显示发生警告的文件的名称

标签 symfony webpack-encore stylelint

运行 stylelint 时,警告的输出不会显示发生错误的文件的名称(有错误时它可以正常工作)。我的文件如下所示:

app.scss

@import './_file-with-error';

_file-with-error.scss

html body {
  color: red;
}

body { // provocate an error 😈
  color: red;
}

我使用 Webpack Encore 和 stylelint 作为 PostCSS 插件,当我构建时,我得到:

michael@machine:~$ yarn encore dev
yarn run v1.21.1
$ /var/www/html/mop/mop/node_modules/.bin/encore dev
Running webpack ...

 WARNING  Compiled with 1 warnings                                                                                                                                     11:47:14 PM

 warning  in ./assets/scss/app.scss

Module Warning (from ./node_modules/postcss-loader/src/index.js):
Warning

(5:1) Expected selector "body" to come before selector "html body" (no-descending-specificity)

Entrypoint app [big] = runtime.js vendors~app.js app.css app.js
Entrypoint home = runtime.js home.js
Entrypoint _tmp_copy = runtime.js
Done in 3.06s.

所以一切都很好,只是我看不到警告来自哪里,我需要文件名。我该如何配置?

设置

webpack.config.js

Encore.enablePostCssLoader();

postcss.config.js

module.exports = {
  plugins: {
    autoprefixer: {},
    stylelint: {},
  },
};

.stylelintrc.json

{
  "extends": "stylelint-config-standard",
  "rules": {
    "no-duplicate-selectors": null
  }
}

最佳答案

您需要add a reporter to your PostCSS pipeline :

The stylelint plugin registers warnings via PostCSS. Therefore, you'll want to use it with a PostCSS runner that prints warnings or another PostCSS plugin whose purpose is to format and print warnings (e.g. postcss-reporter).

例如:

module.exports = {
  plugins: {
    autoprefixer: {},
    stylelint: {},
    'postcss-reporter': { clearReportedMessages: true }
  },
}

或者,您可以使用 official webpack plugin for stylelint .

关于symfony - Stylelint 输出不显示发生警告的文件的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59940087/

相关文章:

create-react-app - create-react-app @import-normalize 上的 stylelint 抛出错误

npm - 从 CLI 运行 stylelint 时出现问题

php - 如何确定登录表单(Symfony 4)拒绝访问的原因?

mysql - 尝试将 sql 脚本导入现有数据库会生成错误

php - Symfony 2,QueryBuilder,具有相同参数的多个andWhere

javascript - 在 app.js Symfony 4 文件中加载 Assets

css - Stylelint : Max Specificity Selector with Regex

php - 如何向 symfony2 中的未绑定(bind)表单字段添加验证

symfony - 如何使用 Webpack Encore 在 Heroku 上编译资源?

javascript - OpenLayers:为什么浏览器中的console.log可以找到该变量