[vue,git]vuecli3 添加githooks,代码提交前校验格式化

vuecli githooks配置官方链接

yorkie实际是fork husky,然后做了一些定制化的改动,使得钩子能从package.json的 "gitHooks"属性中读取

1 添加依赖

npm install yorkie lint-staged pre-commit --save-dev

2 package.json配置

``` 
{
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
    },
  ...
 "gitHooks": {
    "pre-commit": "lint-staged"
  },
   "lint-staged": {
     "*.js": [
       "vue-cli-service lint",
       "git add"
     ],
     "*.vue": [
       "vue-cli-service lint",
       "git add"
     ]
   },
  ...
 "dependencies": {...},
 "devDependencies": {...},
}
```

vue.config.js配置[非必要]

module.exports = {
...
   lintOnSave: process.env.NODE_ENV === 'development',
    devServer: {
       port: port,
       open: true,
       overlay: {
         warnings: false,// warning不显示报错
         errors: true
       },
    // // before: require('./mock/mock-server.js')
    // proxy: {
    //   '/api': {
    //     target: process.env.VUE_APP_BASE_API, // 对应自己的接口
    //     changeOrigin: true,
    //     ws: true,
    //     pathRewrite: {
    //       '^/api': '/'
    //     }
    //   }
    // }
  },
...
}

你可能感兴趣的:([vue,git]vuecli3 添加githooks,代码提交前校验格式化)