一、项目本地新增配置文件:
.vscode\settings.json
{
// editor
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation": true,
"editor.defaultFormatter": "vscode.typescript-language-features",
"[javascript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[vue]": {
"editor.defaultFormatter": "octref.vetur"
},
"[css]": {
"editor.defaultFormatter": "vscode.css-language-features"
},
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[less]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
//javascript
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
//eslint
"eslint.format.enable": false,
"eslint.validate": [
"javascript",
"javascriptreact",
"vue",
"typescript",
"typescriptreact"
],
//vetur
"vetur.format.defaultFormatter.js": "vscode-typescript",
"vetur.format.defaultFormatter.html": "js-beautify-html",
"vetur.format.defaultFormatterOptions": {
"js-beautify-html": {
"wrap_attributes": "force-aligned"
}
},
"vetur.validation.template": false
}
注:
1.会保存时自动格式化、格式化规则和之前保持一致,并且增加了对独立.less文件、独立.html文件的自动格式化。
2.项目内的配置文件优先级会大于全局配置。
二、必须安装的vscode插件:
Vetur、Prettier、ESlint
三、.vscode\settings.json文件需要加入到版本库,但.vscode文件夹下的其它文件需要忽略,因此修改.gitignore文件:
步骤一:
删除原来的.vscode
步骤二:
在文件末尾新增
.vscode/*
!.vscode/settings.json
.vscode