File: get-started.md

package info (click to toggle)
node-husky 9.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 952 kB
  • sloc: sh: 182; javascript: 79; makefile: 9
file content (63 lines) | stat: -rw-r--r-- 1,129 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 快速开始

## 安装

::: code-group

```shell [npm]
npm install --save-dev husky
```

```shell [pnpm]
pnpm add --save-dev husky
```

```shell [yarn]
yarn add --dev husky
# 如果你的项目不是私有的,那么只需要安装 pinst
yarn add --dev pinst
```

```shell [bun]
bun add --dev husky
```

:::

## `husky init` <Badge type="tip" text="推荐" />

`init` 命令简化了项目中的 husky 设置。它会在 `.husky/` 中创建 `pre-commit` 脚本,并更新 `package.json` 中的 `prepare` 脚本。随后可根据你的工作流进行修改。

::: code-group

```shell [npm]
npx husky init
```

```shell [pnpm]
pnpm exec husky init
```

```shell [yarn]
# 由于特殊的注意事项和与其他包管理器的差异,
# 请参考“如何使用”章节。
```

```shell [bun]
bunx husky init
```

:::


## 试一试

恭喜你!你已经成功地用一个命令设置了你的第一个 Git 钩子 🎉。让我们测试一下:

```shell
git commit -m "Keep calm and commit"
# 测试脚本会在每次提交时运行
```

_有关手动设置和更多信息,请参见 [如何使用](how-to.md) 章节_