个人的 commitlint 配置预设。
在你的项目中安装 @hanworks/commitlint-config 包:
pnpm add -D husky lint-staged czg cz-git @hanworks/commitlint-config在你的项目根目录下创建 commitlint.config.js:
// commitlint.config.js
export default {
extends: ['@hanworks/commitlint-config'],
}- 初始化 husky
pnpm husky install- 然后在
package.json添加prepare,保证以后install会自动注册:
{
"scripts": {
"prepare": "husky"
}
}然后执行一次 pnpm install 来触发 prepare。
- 添加 pre-commit hook
.husky/pre-commit
pnpm exec lint-staged- 添加 commit-msg hook
.husky/commit-msg
pnpm exec commitlint --config commitlint.config.js --edit "${1}"- 配置 lint-staged 在
package.json中添加:
{
"lint-staged": {
"*.{js,ts,vue}": "eslint --fix"
}
}- 将以下命令添加到你的脚本 package.json 部分:
{
"scripts": {
"cz": "czg"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-git"
}
}
}