3
使用yarn为新node.js工程添加husky
source link: https://xmanyou.com/add-husky-to-new-node-project-using-yarn/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
17 November 2021
/ husky
使用yarn为新node.js工程添加husky
Husky官方文档的示例都是使用npm来添加husky,但是,如果使用yarn,要如何添加husky模块呢?
1. 添加husky到项目里
yarn add husky -D
或者
yarn add husky --dev
2. 初始化husky
添加以下代码到package.json的scripts中
"scripts": {
"postinstall": "husky install",
...
}
yarn run postinstall
3. 添加git钩子
npx husky add .husky/pre-commit "echo precommit hook works!"
看到以下输出结果表示添加成功
husky - created .husky/pre-commit
检查一下husky的hook文件是否正确创建:
<项目>/.husky/pre-commit
4. 测试钩子
提交一个commit,检查是否有输出
关于Husky: https://typicode.github.io/husky/#/
阿斌
Read more posts by this author.
扫一扫关注微信公众号:耿直的IT男阿斌
聊一聊IT男眼中的世界
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK