husky 初始化

在项目中使用 husky

01 安装 husky

添加 husky

yarn add --dev husky

02 添加一个 commit 的 hook

添加一个 hook

npx husky init

03 确认 script 中有 husky

确认上面步骤里有 husky 的任务

# 任务名
"prepare": "husky"
# 设置
npm pkg set scripts.prepare="husky"

04 手动添加 hook

pre-commit 为例

echo "npm test" > .husky/pre-commit

05 常用生命周期

常用的 husky 的 hook

[
    "pre-commit",
    "pre-merge-commit",
    "prepare-commit-msg",
    "commit-msg",
    "post-commit",
    "applypatch-msg",
    "pre-applypatch",
    "post-applypatch",
    "pre-rebase",
    "post-rewrite",
    "post-checkout",
    "post-merge",
    "pre-push",
    "pre-auto-gc"
]
husky node hooks