1. 配置
- yarn add —dev —exact prettier
- echo {}> .prettierrc.json
- 新建 .prettierignore
build
coverage
lint-staged
- 我们想要每次git commit的时候,自动运行prettier,需要借助pre-commit hook
- npx mrm lint-staged
- 会发现package.json中新添了”husky”和”lint-staged”命令
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,css,md,ts,tsx}": "prettier --write"
}
- 会发现package.json中新添了”husky”和”lint-staged”命令
eslint-config-prettier
- prettier和eslint一起工作的时候会有些冲突,我们需要借助一个包(eslint-config-prettier)来解决这个问题
- yarn add -D eslint-config-prettier
- 在package.json里的”eslintConfig”中加入”prettier” ```json “eslintConfig”: { “extends”: [ …,
- “prettier” ] } ```
commitlint
规范git commit message 规则:https://github.com/conventional-changelog/commitlint/tree/master/@commitlint/config-conventional
- yarn add -D @commitlint/{config-conventional,cli}
- echo “module.exports = {extends: [‘@commitlint/config-conventional’]}” > commitlint.config.js
- 在package.json的”husky”里加上”commit-msg”
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}