Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit10f2973

Browse files
author
kevin
committed
feat: add husky for git commit
1 parent70d5c75 commit10f2973

File tree

4 files changed

+1637
-89
lines changed

4 files changed

+1637
-89
lines changed

‎.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
."$(dirname"$0")/_/husky.sh"
3+
4+
npx --no-install lint-staged

‎README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,57 @@ node_modules
102102

103103
修改 eslint(.eslintrc.js)配置
104104

105+
###自动保存
105106

107+
```
108+
{
109+
"editor.codeActionsOnSave": {
110+
"source.fixAll.eslint": true
111+
},
112+
"editor.formatOnSave": true
113+
}
114+
```
106115

107116
###husky
108117

118+
```
119+
npm install husky lint-staged -D
120+
```
121+
122+
repare 脚本会在 yarn install 之后自动运行,这样依赖你的小伙伴 clone 了你的项目之后会自动安装 husky,这里由于我们已经运行过 yarn install 了,所以我们需要手动运行一次 yarn run prepare,然后我们就会得到一个目录.husky。
123+
124+
`npm run prepare`
125+
126+
会生成,`.husky`文件夹,
127+
128+
接下来我们为我们 git 仓库添加一个 pre-commit 钩子,运行
129+
130+
```
131+
npx husky add .husky/pre-commit "npx --no-install lint-staged"
132+
```
133+
134+
运行之后,会在`.husky`文件夹中生成一个`pre-commit`文件
135+
136+
```
137+
#!/bin/sh
138+
. "$(dirname "$0")/_/husky.sh"
139+
140+
npx --no-install lint-staged
141+
```
142+
143+
接下来我们配置 lint-staged,在 package.json 中添加下面的配置信息
144+
145+
```
146+
"lint-staged": {
147+
"*.{js,vue,ts,jsx,tsx}": [
148+
"prettier --write",
149+
"eslint --fix"
150+
],
151+
"*.{html,css,less,scss,md}": [
152+
"prettier --write"
153+
]
154+
}
155+
156+
```
157+
109158
###router

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp