1.依赖的包(使用yarn commit):
npm i @commitlint/cli @commitlint/config-conventional commitizen cz-conventional-changelog husky -D
2.json配置:
{
"scripts": {
"commit": "git add -A && git-cz"
},"config": {
"commitizen": { "path": "./node_modules/cz-conventional-changelog" } },
"husky": { "hooks": { "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" }
}
}
3. .commitlintrc.js配置文件
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'typeenum': [2, 'always', ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'chore', 'revert', 'other']], },
}