如何在 package.json 中从另一个命令调用一个命令? [英] How to call one command from another in package.json?
本文介绍了如何在 package.json 中从另一个命令调用一个命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在 package.json 中有一些这样的脚本
suppose if i have some script in package.json like this
"scripts": {
"a1": "first command",
"a2": "second command",
"a3": "third command",
}
如果我想在脚本 a3 中运行脚本 a1 和 a2 我该怎么做?这可能吗?我正在使用
and if i want to run script a1 and a2 in the script a3 how can i do this? can this be possible? I am using
节点版本:v6.9.4
node version : v6.9.4
npm 版本:4.3.0
npm version : 4.3.0
我想实现这样的目标
"scripts": {
"a1": "first command",
"a2": "second command",
"a3": "third command && a1 && a2",
}
推荐答案
在脚本中使用 npm run
.例如
"scripts": {
"a1": "first command",
"a2": "second command",
"a3": "third command && npm run a1 && npm run a2",
}
通过 CLI 运行 $ npm run a3
将运行 第三个命令
(不管是什么),然后是 a1
,然后是 a2
.
Running $ npm run a3
via the CLI will run the third command
(whatever that is), followed by a1
, then a2
.
但是,如果通过 CLI 运行 $npm run a3
只是运行 a1
后跟 a2
那么:
However, if running $npm run a3
via the CLI is to only run a1
followed by a2
then:
"scripts": {
"a1": "first command",
"a2": "second command",
"a3": "npm run a1 && npm run a2",
}
这篇关于如何在 package.json 中从另一个命令调用一个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文