添加包git
yarn add @commitlint/cli @commitlint/config-conventional husky -D
配置package.json
github
"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
json
"scripts": { "release": "standard-version" }
執行 yarn release
生成CHANGELOG.md 相似bash
# 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))
yarn add lint-staged -D
配置package.json
markdown
"husky": { "hooks": { // 代碼提交前 執行lint 也能夠配合prettier將代碼直接格式化後提交 "pre-commit": "lint-staged" } }, "lint-staged": { "linters": { "/src/**/*.js": [ "eslint --fix", "git add" ] }, "ignore": [ "/**/*.min.js" ] }
代碼提交以前執行lint 保證代碼格式統一ide