패키지 설치:
npm install husky @commitlint/config-conventional @commitlint/cli --save-dev
package.json 설정: type:module을 제거하거나 "type": "commonjs"로 변경합니다.
Husky 초기화:
npx husky init
commitlint 설정: commitlint.config.cjs 파일을 생성하고 다음 내용을 작성합니다:
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-case': [2, 'always', 'lower-case'],
'type-enum': [
2,
'always',
[
'feat',
'fix',
'design',
'!breaking change',
'!hotfix',
'style',
'refactor',
'comment',
'docs',
'test',
'chore',
'rename',
'remove'
]
],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'body-leading-blank': [2, 'always'],
'footer-leading-blank': [2, 'always'],
},
parserPreset: {
parserOpts: {
issuePrefixes: ['EPIC: #', 'Story: #', 'Task: #']
}
}
};
Husky 훅 설정: .husky/pre-commit 파일:
#!/usr/bin/env sh
npm run lint
npm test
.husky/commit-msg 파일:
#!/usr/bin/env sh
npx --no -- commitlint --edit "$1"
package.json 스크립트 추가:
{
"scripts": {
"prepare": "husky install"
}
}
Git 커밋 템플릿 설정 (선택사항): .gitmessage.txt 파일 생성:
<type>: <subject>
<body>
EPIC: #
Story: #
Task: #
Git 설정에 템플릿 추가:
git config --local commit.template .gitmessage.txt
주의사항: