# 使用 husky
+ lint-staged
+ cz-git
助力团队编码规范
# 安装依赖
npm i -D husky lint-staged cz-git cross-env
1
# 修改 package.json
"scripts": {
"husky:init": "cross-env-shell \"npx husky init && echo 'npm run lint-staged' > .husky/pre-commit\"",
"lint-staged": "lint-staged"
},
"devDependencies": {
"cz-git": "^1.11.0",
"husky": "^9.1.7",
"lint-staged": "^10.5.4",
"cross-env": "^7.0.3"
},
"config": {
"commitizen": {
"path": "cz-git"
}
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js}": [
"eslint --fix",
"git add"
],
"*.{less,css}": [
"stylelint --fix",
"git add"
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 初始化 husky
npm run husky:init
1
# 效果
← 规范git提交利器指南 前端开发规范 →