npm: disable postinstall script for package

2019-01-30 17:00发布

问题:

Is it any npm option exist to disable postinstall script while installing package? Or for rewriting any field from package.json?

回答1:

It's not possible to disable only postinstall scripts. However, you can disable all scripts using:

$ npm install --ignore-scripts

As delbertooo mentionned in the comments, this also disables the scripts of the dependencies.



回答2:

To do this for your own library, I recommend something simple like:

#!/usr/bin/env bash

## this is your postinstall.sh script:

set -e;

if [ "$your_pkg_skip_postinstall" == "yes" ]; then
  echo "skipping your package's postinstall routine.";
  exit 0;
fi

then do your npm install with:

your_pkg_skip_postinstall="yes" npm install


标签: node.js npm