Skip to content

Commit

Permalink
docs: use NODE_ENV to conditionally install husky (#1310)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
forivall committed Oct 26, 2023
1 parent 46325f8 commit 06df89a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ Alternatively, you can ignore scripts during installation. Be cautious, this arg
npm ci --omit=dev --ignore-scripts
```

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.

```shell
npm pkg set scripts.prepare="node -e \"if (process.env.NODE_ENV !== 'production') { require('husky').install() }\""
```

### With a custom script

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

0 comments on commit 06df89a

Please sign in to comment.