一、 husky

安装

pnpm install -D husky

生成husky 配置文件

如果文件中有.git文件,那么直接执行

npx husky-init

如果没有,那么先执行git init

结果:

PS F:\company_project\demo\youlahoutaijiexi\vite-project> git init
Initialized empty Git repository in F:/company_project/demo/youlahoutaijiexi/vite-project/.git/
PS F:\company_project\demo\youlahoutaijiexi\vite-project> npx husky-init
husky-init updating package.json
  "husky install" command already exists in prepare script, skipping.
husky - Git hooks installed
husky - created .husky/pre-commit

please review changes in package.json

执行完成以后,在根目录下生成一个.husky 目录。
有来团队后台项目-解析5-LMLPHP
修改pre-commit 中的内容:

npm run lint:lint-staged

在package.json 中插入:

  "lint-staged": {
   
    "*.{js,ts}": [
      "eslint --fix",
      "prettier --write"
    ],
    "*.{cjs,json}": [
      "prettier --write"
    ],
    "*.{vue,html}": [
      "eslint --fix",
      "prettier --write",
      "stylelint --fix"
    ],
    "*.{scss,css}": [
      "stylelint --fix",
      "prettier --write"
    ],
    "*.md": [
      "prettier --write"
    ]
  },

二、配置commitlint

安装commitlint

pnpm add
03-13 14:37