From 06df89a8272a80df21d43bc187aba4d2f39b5770 Mon Sep 17 00:00:00 2001 From: Emily Marigold Klassen <760204+forivall@users.noreply.github.com> Date: Thu, 26 Oct 2023 02:26:47 -0700 Subject: [PATCH] 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. --- docs/guide.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/guide.md b/docs/guide.md index c520d9f2b..179256b21 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -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.