【问题标题】:How to call one command from another in package.json?如何在 package.json 中调用另一个命令?
【发布时间】:2017-08-16 03:26:58
【问题描述】:

假设我在 package.json 中有这样的脚本

 "scripts": {
    "a1": "first command",
    "a2": "second command",
    "a3": "third command",
      
  }

如果我想在脚本 a3 中运行脚本 a1a2 我该怎么做?这可能吗?我正在使用

节点版本:v6.9.4

npm 版本:4.3.0

我想实现这样的目标

"scripts": {
    "a1": "first command",
    "a2": "second command",
    "a3": "third command && a1 && a2",
      
  }

【问题讨论】:

    标签: npm package.json


    【解决方案1】:

    在脚本中使用npm run。例如

    "scripts": {
      "a1": "first command",
      "a2": "second command",
      "a3": "third command && npm run a1 && npm run a2",
    }
    

    通过 CLI 运行 $ npm run a3 将运行 third command(无论是什么),然后是 a1,然后是 a2

    但是,如果通过 CLI 运行 $npm run a3 仅运行 a1 后跟 a2 则:

    "scripts": {
      "a1": "first command",
      "a2": "second command",
      "a3": "npm run a1 && npm run a2",
    }
    

    【讨论】:

      猜你喜欢
      • 2020-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-01
      • 1970-01-01
      相关资源
      最近更新 更多