# 配置 husky、lint-staged、@commitlint/cli
- husky:一个为 git 客户端增加 hook 的工具
- lint-staged:仅对 Git 代码暂存区文件进行处理,配合 husky 使用
- @commitlint/cli:让 commit 信息规范化
# 1. 创建 git 仓库
# 2. 安装
|  | yarn add husky@9.1.3 -D  | 
|  | yarn add lint-staged@^15.2.7 -D | 
|  | yarn add @commitlint/cli@^19.3.0 -D | 
|  | yarn add @commitlint/config-conventional@^19.2.2 -D | 
# 3. 生成 .husky 的文件夹
# 4. 修改.husky/pre-commit
|  | #!/usr/bin/env sh | 
|  | npx --no-install lint-staged | 
# 5. 修改.husky/commit-msg
|  | #!/usr/bin/env sh | 
|  | npx --no-install commitlint --edit $1 | 
# 6. 修改 package.json
|  | "lint-staged": { | 
|  |   "src/**/*.{js,ts,vue}": [ | 
|  |     "yarn run lint", | 
|  |     "prettier --write" | 
|  |   ] | 
|  | } | 
# 7. 新建 commitlint.config.cjs
提示:由于 package.json 的 "type": "module" ,需将 commonjs 文件显示声明为 .cjs
|  | module.exports = { | 
|  |   extends: ['@commitlint/config-conventional'], | 
|  | }; | 
提交格式:
|  | git commit -m <type>[optional scope]: <description> //注意冒号后面有空格 | 
|  | - type:提交的类型(如新增、修改、更新等) | 
|  | - optional scope:涉及的模块,可选 | 
|  | - description:任务描述 | 
type 类型:
| 类别 | 含义 | 
|---|
| feat | 新功能 | 
| fix | 修复 bug | 
| style | 样式修改(UI 校验) | 
| docs | 文档更新 | 
| refactor | 重构代码 (既没有新增功能,也没有修复 bug) | 
| perf | 优化相关,比如提升性能、体验 | 
| test | 增加测试,包括单元测试、集成测试等 | 
| build | 构建系统或外部依赖项的更改 | 
| ci | 自动化流程配置或脚本修改 | 
| revert | 回退某个 commit 提交 | 
# 8. 示范(非规范提交,将提交失败)
|  | git commit -m 'feat: 增加 xxx 功能' | 
|  | git commit -m 'bug: 修复 xxx 功能' |