安装
install这三个包,贴上版本
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"husky": "^6.0.0",
请按顺序配置
package.json加上scripts
"prepare": "husky install"
如果你已经安装过依赖了直接执行这行命令 npm run prepare
如果你没有安装过依赖命令会在install后自动执行
根目录创建文件commitlint.config.js
/**
* feat:新增功能
* fix:bug 修复
* docs:文档更新
* style:不影响程序逻辑的代码修改(修改空白字符,格式缩进,补全缺失的分号等,没有改变代码逻辑)
* refactor:重构代码(既没有新增功能,也没有修复 bug)
* perf:性能, 体验优化
* test:新增测试用例或是更新现有测试
* build:主要目的是修改项目构建系统(例如 glup,webpack,rollup 的配置等)的提交
* ci:主要目的是修改项目继续集成流程(例如 Travis,Jenkins,GitLab CI,Circle等)的提交
* chore:不属于以上类型的其他类型,比如构建流程, 依赖管理
* revert:回滚某个更早之前的提交
*/
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [
2,
'always',
['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore', 'revert'],
],
'subject-full-stop': [0, 'never'],
'subject-case': [0, 'never'],
},
};
执行
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'