关于让项目都挂上钩子(经验证,最新版本的Husky,使用这样的配置实际上是不生效的)
husky 6.0 实测不生效。1.3.1下述配置使用正常。
{"name": "xxxx","version": "1.0.0","description": "","main": "index.js","dependencies": {"cz-conventional-changelog": "^3.3.0","husky": "^1.3.1","validate-commit-msg": "^2.14.0"},"devDependencies": {},"scripts": {"test": "echo \"Error: no test specified\" && exit 1","commitmsg": "validate-commit-msg"},"husky": {"hooks": {"commit-msg": "validate-commit-msg"}},"config": {"commitizen": {"path": "./node_modules/cz-conventional-changelog"}},"keywords": [],"author": "","license": "ISC"}
通过安装 cz + 配置 config => 实现 git cz 的激活
这也是以下配置的作用
"cz-conventional-changelog": "^3.3.0",
"config": {"commitizen": {"path": "./node_modules/cz-conventional-changelog"}},
Husky版本问题解决
https://blog.csdn.net/github_39553323/article/details/115312884
https://zhuanlan.zhihu.com/p/356924268(解释了原理,很清晰)
那么,我们来实现一个最新版本 Husky 的钩子
学到了什么
package.json 的一些默认约定
- scripts 里面的 ‘prepare’ 会在 npm install 的时候,自动执行——【所以在这里挂在 husky install,就能够帮我们在初始化项目的时候,创建 huksy 目录】
- 顺带回忆起——如commonJS的默认约定,会从 main 指向的 js 开始寻找
{"main": "self.js"}
