npm: disable postinstall script for package

前端 未结 4 1154
傲寒
傲寒 2020-12-07 13:35

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

4条回答
  •  一生所求
    2020-12-07 14:16

    I wanted to disable postinstall script for my project but wanted all scripts of my project's dependencies to run when I do npm install. This is what I ended up doing.

    1. Create a script ./scripts/skip.js
    if (process.env.SKIP_BUILD) {
        process.exit(0);
    } else {
        process.exit(1);
    }
    
    1. In your package.json file
     "scripts": {
      ...
      "postinstall": "node ./scripts/skip.js || npm run build",
      ...
     }
    

    now just set the environment variable SKIP_BUILD=1 to prevent your package from building and your dependencies will build just fine

    SKIP_BUILD=1 npm install
    

提交回复
热议问题