Stylelint
The Stylelint checker reports CSS problems using Stylelint and your project's Stylelint configuration.
Set up
Install Stylelint (version 16.26.1 or later),
meow, and the configs and plugins your Stylelint config uses. The checker usesmeowto parselintCommand:bashpnpm add -D stylelint meowbashnpm install -D stylelint meowbashyarn add -D stylelint meowbashbun add -d stylelint meowEnable the checker with a
lintCommand. Use the same command you'd run in your terminal or CI:tschecker({ stylelint: { lintCommand: 'stylelint "./src/**/*.{css,vue}"', }, })
How lintCommand is used
- In build mode, the checker runs
lintCommandas a Stylelint CLI command from the Vite root. The first word must bestylelint; it runs thestylelintbinary installed in your project. - In dev mode, the checker translates the CLI flags in
lintCommandto Stylelint Node.js API options, and lints the files that match its first file pattern. When a file changes, only that file is linted again.
Don't add --fix to lintCommand; Stylelint would modify your files while the dev server or build runs.
Watch fewer files
By default, dev mode watches the whole Vite root, excluding node_modules and .git. In large projects, this can be slow or fail with EMFILE: too many open files. Set watchPath to watch only the directories you lint:
checker({
stylelint: {
lintCommand: 'stylelint "./src/**/*.{css,vue}"',
watchPath: './src',
},
})Override dev mode options
dev.overrideConfig takes Stylelint options that override the ones translated from lintCommand, in dev mode only:
checker({
stylelint: {
lintCommand: 'stylelint "./src/**/*.css"',
dev: {
overrideConfig: {
cache: true,
},
},
},
})The final options are { cwd: root, ...translatedOptions, ...dev.overrideConfig }.
Options
| Option | Type | Default | Description |
|---|---|---|---|
lintCommand | string | Required | Stylelint CLI command. See How lintCommand is used. |
watchPath | string | string[] | The Vite root | Paths to watch in dev mode, relative to the root. |
dev.overrideConfig | Stylelint.LinterOptions | undefined | Options that override the ones translated from lintCommand in dev mode. |
dev.logLevel | ('error' | 'warning')[] | ['error', 'warning'] | Diagnostic levels to report in dev mode. |
dev.debounceMs | number | 300 | Time in milliseconds to wait after a change before linting. Changes within this window are linted together. |
