Skip to content

Commit 06df89a

Browse files
authoredOct 26, 2023
docs: use NODE_ENV to conditionally install husky (#1310)
See npm's documentation at https://docs.npmjs.com/cli/v8/commands/npm-install#omit > If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment > variable will be set to `'production'` for all lifecycle scripts.
1 parent 46325f8 commit 06df89a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed
 

‎docs/guide.md

+6
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ Alternatively, you can ignore scripts during installation. Be cautious, this arg
8181
npm ci --omit=dev --ignore-scripts
8282
```
8383

84+
When using `--omit=dev`, `npm` will set `NODE_ENV` to `production` for lifecycle scripts, so another alternative is to check it to conditionally install husky.
85+
86+
```shell
87+
npm pkg set scripts.prepare="node -e \"if (process.env.NODE_ENV !== 'production') { require('husky').install() }\""
88+
```
89+
8490
### With a custom script
8591

8692
You can create a custom JS script and conditionally require husky and install hooks.

0 commit comments

Comments
 (0)
Please sign in to comment.