Commitlint 配置
-
新增包
yarn add @commitlint/cli @commitlint/config-conventional husky -D
-
配置
package.json
"husky": { "hooks": { // 此處如果不使用husky 需要將HUSKY_GIT_PARAMS 替換為 GIT_PARAMS "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" } }, "commitlint": { "extends": [ "@commitlint/config-conventional" ] }
- 效果: 程式碼提交的格式不符合標準 就會直接被拒絕。在團隊協作時提交歷史的回溯需要有良好的提交歷史
版本管理
yarn add standard-version -D
配置package.json
"scripts": {
"release": "standard-version"
}
執行 yarn release
生成CHANGELOG.md 類似
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
<a name="1.0.3"></a>
## 1.0.3 (2018-12-05)
### Features
* **lint:** 新增commitlint配置 ([faee26d](http://url/commits/faee26d))
* **lint:** 簡化commitlint配置 ([affeb7d](http://url/commits/affeb7d))
ESLint配置
yarn add lint-staged -D
配置package.json
"husky": {
"hooks": {
// 程式碼提交前 執行lint 也可以配合prettier將程式碼直接格式化後提交
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"linters": {
"/src/**/*.js": [
"eslint --fix",
"git add"
]
},
"ignore": [
"/**/*.min.js"
]
}
程式碼提交之前執行lint 保證程式碼格式統一