1,
下载插件
yarn add --dev --exact eslint-config-prettier
yarn add --dev --exact prettier
2,vscode 下载prettier扩展
3,创建 .prettierrc.js文件
.prettierrc.js配置
module.exports = {
printWidth: 80,
singleQuote: true,
tabWidth: 4,
jsxBracketSameLine: false,
useTabs: false,
semi: true,
bracketSpacing: true,
eslintIntegration: true,
vueIndentScriptAndStyle: true,
trailingComma: 'none',
arrowParens: 'avoid',
endOfLine: 'auto'
};
4,创建.prettierignore文件
.prettierignore配置
node_modules/
build/
*-lock*
*.lock
public/
**/font/
docs/
5,最外层添加setting.json 文件 保存文件自动格式化
配置
{
"editor.rulers": [80,120],
"editor.formatOnSave": true,
"editor.tabSize": 4,
"editor.insertSpaces": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
}
}
.eslintrc.js文件中添加 兼容eslint和orettier