vue3+vite+ts 配置commit强制码提交规范配置 commitlint

配置 git 提交时的 commit 信息,统一提交 git 提交规范

安装命令:

bash 复制代码
npm install -g commitizen
npm i cz-customizable
npm i @commitlint/config-conventional @commitlint/cli -D

文件配置

根路径创建文件

commitlint.config.js

javascript 复制代码
module.exports = {
  // 继承的规则
  extends: ['@commitlint/config-conventional'],
}

.husky文件创建 commit-msg

javascript 复制代码
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit "$1"

package.json添加代码

javascript 复制代码
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  },

提交方式

1,手动使用commit

bash 复制代码
git commit -m 'feat(custom): 测试提交'

2.配合vscode中的插件快捷提交 git-commit-plugin

在vscode的设置中加入配置,不然会有小图标导致commit不通过

javascript 复制代码
 "GitCommitPlugin.ShowEmoji":false,//去除commIt插件图标

3.以是使用npm脚本进行快捷提交

在根目录下新建 .cz-config.cjs 文件并写入配置 之后就可以用 git cz 来代替 git commit

.cz-config.cjs

javascript 复制代码
module.exports = {
    // 可选类型
    types: [
      { value: 'feat', name: 'feat:     新功能' },
      { value: 'fix', name: 'fix:      修复' },
      { value: 'docs', name: 'docs:     文档变更' },
      { value: 'style', name: 'style:    代码格式(不影响代码运行的变动)' },
      {
        value: 'refactor',
        name: 'refactor: 重构(既不是增加feature,也不是修复bug)'
      },
      { value: 'perf', name: 'perf:     性能优化' },
      { value: 'test', name: 'test:     增加测试' },
      { value: 'chore', name: 'chore:    构建过程或辅助工具的变动' },
      { value: 'revert', name: 'revert:   回退' },
      { value: 'build', name: 'build:    打包' }
    ],
    // 消息步骤
    messages: {
      type: '请选择提交类型(必填):',
      subject: '请简要描述提交(必填):',
      customScope: '请输入修改范围(可选):',      
      body: '请输入详细描述(可选):',
      footer: '请输入要关闭的issue(可选):',
      confirmCommit: '确认使用以上信息提交?(y/n/e/h)'
    },
    // 跳过问题
    skipQuestions: ['body', 'footer'],
    // subject文字长度默认是72
    subjectLimit: 72
  }

在package.json中进行新增

javascript 复制代码
  "scripts": {
    "commit":"git cz"
  },  
"config": {
    "commitizen": {
      "path": "node_modules/cz-customizable"
    },
    "cz-customizable": {
      "config": ".cz-config.cjs"
    }
  },

执行npm 中的commit脚本

相关推荐
wuhen_n5 分钟前
鼠标悬浮特效:常见6种背景类悬浮特效
前端·css·css3·html5
娃哈哈哈哈呀13 分钟前
组件通信-v-model
java·服务器·前端
ApiHug1 小时前
ApiHug SDK 1.3.5 Vue 框架 - 预览版
前端·javascript·vue.js·spring·vue·apihug·apismart
旺代1 小时前
React Router
前端·javascript·react.js
进取星辰1 小时前
18、状态库:中央魔法仓库——React 19 Zustand集成
前端·react.js·前端框架
心海资源2 小时前
Java多语言DApp质押挖矿盗U源码(前端UniApp纯源码+后端Java)
java·前端·uni-app
小杨升级打怪中2 小时前
前端面经-VUE3篇(二)--vue3组件知识(二)依赖注入、异步组件、生命周期、组合式函数、插件
开发语言·前端·javascript
羊啊羊372 小时前
Vue 3 事件总线详解:构建组件间高效通信的桥梁
前端·javascript·vue.js
MYmayue2 小时前
vue3封装全局方法
前端·javascript·vue.js
GISer_Jing3 小时前
前端面试常问问题[From CV]
前端·javascript·面试