原文链接: vue 提交前进行代码检查和修复
安装
npm install husky --save-dev
npm install pre-commit --save-dev
yarn add husky --dev
yarn add pre-commit --dev
使用vue-cli3 创建的工程
添加gitHooks 字段, 指定在提交前执行一些命令
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint"
},
"gitHooks": {
"pre-commit": "echo hello && npm run test:unit && npm run lint"
},
or
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint",
"pre-commit":"echo hello && npm run test:unit && npm run lint"
},
"gitHooks": {
"pre-commit": "npm run pre-commit"
},