目前项目js可以保存代码时格式化,但是css不行(快捷键可以)
下面是配置:
- vscode配置 .vscode/settings.json
{
"editor.tabSize": 2, // tab缩进
"editor.formatOnSave": false,
// 自动修复css
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
// 自动修复JS
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
// 配置 ESLint 检查的文件类型
"eslint.validate": [
"javascript",
"html",
"javascriptreact", // react jsx
"typescript", // ts
"typescriptreact" // react tsx
]
}
- prettier配置
module.exports = {
printWidth: 100,
endOfLine: 'auto',
singleQuote: true,
semi: false,
trailingComma: 'none'
}
有没有大神懂这块的,给看看问题在哪?
你 js 格式化走的是 eslint 的。并不是 prettier 。
所以对应的你可以上 stylelint。