使用项目的其他命令运行npm install

时间:2018-11-22 11:47:02

标签: javascript node.js

有没有办法在后台运行命令“ npm install” 其他命令,例如postinstall等。我知道您可以运行npm run <scriptName>但 不确定在npm install命令期间如何从(package.json的)脚本部分运行某些命令。

我尝试阅读有关内容,但未找到任何提示... https://michael-kuehnel.de/tooling/2018/03/22/helpers-and-tips-for-npm-run-scripts.html

1 个答案:

答案 0 :(得分:3)

  "scripts": {
    "preinstall": "node pre.js",
    "postinstall": "node post.js"
  }

您可以在将在该命令之前和之后执行的任何命令之前有一个前置和后置术语。可以是任何命令

例如:-

  "scripts": {
    "check1": "node run.js",
    "precheck1": "node pre.js",
    "postcheck1": "node post.js"
  }

希望这可以解决您的问题。