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脚本

相关推荐
余生H6 分钟前
前端的全栈混合之路Meteor篇:关于前后端分离及与各框架的对比
前端·javascript·node.js·全栈
程序员-珍9 分钟前
使用openapi生成前端请求文件报错 ‘Token “Integer“ does not exist.‘
java·前端·spring boot·后端·restful·个人开发
axihaihai13 分钟前
网站开发的发展(后端路由/前后端分离/前端路由)
前端
流烟默25 分钟前
Vue中watch监听属性的一些应用总结
前端·javascript·vue.js·watch
2401_8572979135 分钟前
招联金融2025校招内推
java·前端·算法·金融·求职招聘
茶卡盐佑星_1 小时前
meta标签作用/SEO优化
前端·javascript·html
Ink1 小时前
从底层看 path.resolve 实现
前端·node.js
金灰1 小时前
HTML5--裸体回顾
java·开发语言·前端·javascript·html·html5
茶卡盐佑星_1 小时前
说说你对es6中promise的理解?
前端·ecmascript·es6
Promise5201 小时前
总结汇总小工具
前端·javascript