在多人协作的背景下, git 仓库和 workflow 的作用很重要. 而对于 commit 提交的信息说明存在一定规范.
安装
npm install --save-dev lint-staged
在package.json中配置 lint-staged
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --single-quote --write",
"git add"
]
}
在做前端工程化时husky可以说是一个必不可少的工具. husky可以让我们向项目中方便添加git hooks.
npm install -D husky
在package.json中配置 husky
{
"husky": {
"hooks": {
"pre-commit": "lint-staged", // 在commit之前先执行lint-staged
"commit-msg": "commitlint -e $HUSKY_GIT_PARAMS" // 校验commit时添加的备注信息是否符合我们要求的规范
}
}
}
安装
npm install --save-dev @commitlint/config-conventional @commitlint/cli
commitlint.config.js
module.exports = {
extends: ['@commitlint/config-conventional']
}
build:主要目的是修改项目构建系统(例如 glup,webpack,rollup 的配置等)的提交
ci:主要目的是修改项目继续集成流程(例如 Travis,Jenkins,GitLab CI,Circle等)的提交
docs:文档更新
feat:新增功能
merge:分支合并 Merge branch ? of ?
fix:bug 修复
perf:性能, 体验优化
refactor:重构代码(既没有新增功能,也没有修复 bug)
style:不影响程序逻辑的代码修改(修改空白字符,格式缩进,补全缺失的分号等,没有改变代码逻辑)
test:新增测试用例或是更新现有测试
revert:回滚某个更早之前的提交
chore:不属于以上类型的其他类型