前端项目工程化
husky :https://typicode.github.io/husky/zh/
lint-staged:https://github.com/lint-staged/lint-staged
commitlint:https://commitlint.js.org/reference/configuration.html
commit 提交规范
| key | value |
|---|---|
| feat | 新增 feature |
| fix | 修复 bug |
| docs | 仅仅修改了文档,比如 README, CHANGELOG, CONTRIBUTE 等等 |
| style | 不改变代码逻辑。仅仅修改了空格、格式缩进、逗号等等 |
| refactor | 代码重构,没有加新功能或者修复 bug |
| perf | 优化相关,比如提升性能、体验 |
| test | 测试用例,包括单元测试、集成测试等 |
| chore | 改变构建流程、或者增加依赖库、工具等 |
| revert | 回滚到上一个版本 |
跳过 Git 钩子
单次跳过 -n/--no-verify
sh
git commit -m "..." -n临时禁用所有 Git 钩子
sh
HUSKY=0 git commit -m "..."更长的禁用
sh
export HUSKY=0 # 禁用所有 Git 钩子
git commit -m "..."
git commit -m "..."
unset HUSKY # 重新启用钩子重新开始搭建
sh
pnpm add husky -D
# npx husky init
# pnpm exec husky init
pnpm husky initsh
pnpm add lint-staged eslint -D
pnpm add @commitlint/cli @commitlint/config-conventional -Dlint-staged 配置不多,可以直接加在 package.json 中
json
"lint-staged": {
"*.{js,jsx,ts,tsx,vue}": [
"prettier --write"
]
},lint-staged 用最标准的用法就行了,不要自己乱加! lint-staged 就推荐 prettier 与 eslint 即可
创建 .commitlintrc.js
js
module.exports = { extends: ["@commitlint/config-conventional"] };参考
参考 1: https://juejin.cn/post/6982192362583752741
参考 2: https://blog.esonwong.com/husky/
参考 3bili: https://gitee.com/liguangtao_home/course/tree/master/husky