鍍金池/ 問答/HTML/ 使用postcss的stylelint插件無法讀取.stylelintrc的配置

使用postcss的stylelint插件無法讀取.stylelintrc的配置項

使用vscodestylelint插件能正常檢查css文件,但是使用webpack + postcss-loader + stylelint插件構(gòu)建時總是提示css文件書寫不合規(guī)范, postcss配置如下:

{
    loader: 'postcss-loader',
    options: {
        sourceMap: true,
        plugins: [
            require('postcss-import')({
                root: path.join(__dirname, './'),
                path: [path.join(__dirname, './src/common/css')]
            }),
            require('stylelint')({
                configFile: './.stylelintrc.json'
            }),
            require('postcss-cssnext')()
           
        ]
    }
}

構(gòu)建時報錯

src/components/footer/style.css
7:1     ?  Expected empty line before rule (rule-empty-line-before) [stylelint]
12:1    ?  Expected empty line before rule (rule-empty-line-before) [stylelint]
...
/* footer */
.footer-bottom {
    padding-top: 1px;
    background-color: #1f1f1f;
}

.footer .transverse-thread {
    width: 30px;
    text-align: left;
}

.footer-data-list {
    float: right;
    margin-top: 50px;
}

但是書寫css并沒有檢測到此錯誤

回答
編輯回答
卟乖

style-lint前置即可解決該問題

{
    loader: 'postcss-loader',
    options: {
        sourceMap: true,
        plugins: [
            require('stylelint')(),
            require('postcss-import')({
                root: path.join(__dirname, './'),
                path: [path.join(__dirname, './src/common/css')]
            }),
            require('postcss-cssnext')()
           
        ]
    }
}

具體原因我也不大清楚,官方也沒見相關(guān)文檔,但是這樣做能解決該問題

2017年9月7日 20:19