Skip to content

stylelint 生态

安装

bash
pnpm add stylelint @stylistic/stylelint-plugin stylelint-config-recess-order stylelint-config-recommended-less stylelint-prettier less -D

配置

根目录下创建 stylelint.config.mjs 文件

js
/** @type {import('stylelint').Config} */
export default {
  root: true,
  extends: ['stylelint-config-standard', 'stylelint-config-recess-order', 'stylelint-config-recommended-less'],
  overrides: [
    {
      customSyntax: 'postcss-html',
      files: ['*.(html|vue)', '**/*.(html|vue)'],
      rules: {},
    },
  ],
  plugins: ['@stylistic/stylelint-plugin', 'stylelint-prettier'],
  rules: {
    'prettier/prettier': true,
  },
}

package.json 文件添加

json
{
  "scripts": {
    "stylelint": "stylelint '**/*.{vue,css,less,scss}' --fix"
  }
}