prettier
- 安装
pnpm add --save-dev --save-exact prettier
- 创建一个空的配置文件
.prettierrc
node --eval "fs.writeFileSync('.prettierrc','{}\n')"
配置.prettierrc
例如:
{
"experimentalTernaries": false,
"printWidth": 120,
"tabWidth": 2,
"useTabs": true,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"bracketSpacing": true,
"bracketSameLine": true,
"arrowParens": "avoid",
"vueIndentScriptAndStyle": true,
"trailingComma": "none",
"endOfLine": "lf"
}
- 创建一个
.praitrignore
文件,让Prettier CLI和编辑器不格式化哪些文件
node --eval "fs.writeFileSync('.praitrignore','')"
例如:
# .praitrignore
build
coverage
node_modules
dist
- 在
package.json
中配置命令
"scripts": {
"prettier": "npx prettier . --write"
}