I noticed this was attempted: https://github.com/vuejs-templates/webpack/pull/154 and closed (For good reason)
But i wondered if anyone has a setup for this currently?
I think is possible to do it with htmlhint, but currently only supports jshint and csslint, maybe if someone can make a htmlhint rule for stylelint.
Actually we could use <style src="/path/of/style/file"/> then just lint the style file as usual.
Touch .stylelintrc
{
"processors": ["stylelint-processor-html"],
"extends": "stylelint-config-standard"
}
Install
npm i stylelint -D
npm i stylelint-processor-html -D
npm i stylelint-config-standard -D
Add lint:css to package.json
"scripts": {
"lint:css": "stylelint '**/*.vue' --syntax scss"
},
npm run lint:css 馃懟 @yisibl that works for me, swear i tried this before!
I'm wondering if there's a way to get stylelint to report this to sublimelinter, although it works great from the command line, it doesn't work actively while typing in sublime. Have you or anyone else had any luck with that? Also, @yisibl thanks for posting this, helped me get started.
For the record, this is working configuration for webpack:
npm i --save-dev stylelint stylelint-processor-html stylelint-config-standard stylelint-webpack-plugin
.stylelintrc{
"processors": ["stylelint-processor-html"],
"extends": "stylelint-config-standard"
}
build/webpack.dev.conf.js for Vue webpack template)//...
var StylelintPlugin = require('stylelint-webpack-plugin')
{
//...
plugins: [
//...
new StylelintPlugin({
files: ['**/*.vue']
})
]
}
I published an article which includes both solutions and explains two additional things (configuration rules and errors when starting the dev server).
@bkzl i follow your config, use the stylelint-webpack-plugin, it can work, but the line number of error reporter is incorrect for .vue file.

@wenkanglin I immediately fix these errors while I code so I didn't even notice that. There is a corresponding issue: ccbikai/stylelint-processor-html/issues/1
try @mapbox/stylelint-processor-arbitrary-tags instead stylelint-processor-html
"scripts": {
"lint:css": "stylelint '*/.vue' --syntax scss"
},
Can not add single quotation marks in windows. Otherwise it will report the following error.
Error: '*/.vue' does not match any files
at globby.then.filePaths
The following setting worked well in windows 10
"scripts": {
"lint:css": "stylelint **/*.vue"
},
stylelint-webpack-plugin or stylelint-processor-html not support automatically fixes.
Related:
stylelint/stylelint#2596
Issue moved to vuejs/011.vuejs.org #6 via ZenHub
Using the @yisibl solution i can't make it works using postcss.
@equinusocio The latest version of stylelint can directly support *.vue files, but you need to delete processors in the configuration file.
If you need to use other postcss tool, not just stylelint, you can use this way:
npm i --save postcss postcss-syntax postcss-html
postcss(plugins).process(source, {
syntax: require('postcss-syntax')
}).then((result) => {
// An alias for the result.css property. Use it with syntaxes that generate non-CSS output.
result.content
});
@gucong3000 Thank you man. This did the trick. There is a documentation somewhere about that?
There is a documentation somewhere about that?
Not at the moment.
@gucong3000 Hi, I cannot get stylelint autofix to work with .vue files? Any idea why?
@hiendv please update stylelint >= v9 then try this command:
stylelint --fix `src/**/*.vue`
There is a documentation somewhere about that?
@gucong3000 This solution doesn't works anymore
https://github.com/vuejs/vue-loader/issues/303#issuecomment-412399156
postcss.config.js
module.exports = {
syntax: require("postcss-syntax"),
plugins: {
"postcss-preset-env": {
stage: 0,
autoprefixer: {
grid: true
}
}
}
};
Defining the syntax package break all the plugins. Removing it stylelint will throw errors parsing the html template. I'm using latest versions of all.
@equinusocio
Maybe you can upload a zip package that contains these errors so I could help you debug them.
After trying many things, I got stylelint autofix to work with .vue files in vscode using SaveOnRun extension.
added below config in the settting.json:
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".vue",
"cmd": "stylelint --fix ${file}"
}
]
},
Better solution would be appreciated!
@mudin good job, saved the day
Most helpful comment
Touch
.stylelintrcInstall
Add
lint:csstopackage.jsonnpm run lint:css馃懟