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

相关推荐
swipe4 分钟前
04|(前端转后全栈)前端状态为什么不够用?从页面数据到 MySQL 持久化
前端·后端·全栈
橘子星5 分钟前
别光看教程!手把手拆解 React Todo 项目,一文吃透 5 个核心概念
前端·javascript
大白要努力!11 分钟前
纯前端实现 PDF 加水印工具 —— 零后端、支持中文、实时预览
前端·pdf·html
石小石Orz13 分钟前
TRAE SOLO实战:实现一个桌面3D助手
前端·人工智能
蜡台19 分钟前
使用 uni-popup 实现数据选择器Data-Picker
前端·javascript·html·uniapp·uni-popup·data-picker
拆房老料20 分钟前
BaseMetas FileView 1.2.0 发布:Office/WPS 大文件预览与内存安全优化实测
前端·产品运营·开源软件
blns_yxl23 分钟前
Promise封装Fetch + 重试机制(HTML+JS)
前端·javascript·html
Elastic 中国社区官方博客28 分钟前
使用重新设计的 AutoOps 更快地进行 Elasticsearch 问题排查
大数据·运维·前端·人工智能·elasticsearch·搜索引擎·全文检索
无巧不成书021833 分钟前
Vue+Vue-CLI全平台零基础搭建教程
前端·javascript·vue.js·vue·前端开发·vue-cli·前端环境搭建