从另一个脚本调用npm脚本并传递参数

huangapple go评论94阅读模式
英文:

Call npm script from another script and pass arguments

问题

"script-a" 是一个脚本,它的定义在我的 package.json 文件中:

"script-a": "npm run script-b",
"script-b": "ts-node ./src/the-script.ts"

假设 "script-b" 支持一个名为 "logging" 的参数。那么,你可以这样调用它:

npm run script-b --logging

你是否可以在调用 "script-a" 时将参数 "logging" 传递给 "script-b" 呢?看起来是这样的:

npm run script-a --logging
英文:

Let's say I have two scripts defined in my package json:

"script-a": "npm run script-b",
"script-b": "ts-node ./src/the-script.ts",

Let's say script-b accepts an argument logging. So I could do the following

npm run script-b --logging

Is it somehow possible to call script-a but pass the argument logging to the call of script-b.
Looking like this:

npm run script-a --logging

答案1

得分: 1

我不确定我是否正确理解你想要做什么,但你可以像这样传递参数:

npm run script-a -- --logging
英文:

I'm not sure if I understand correctly what you want to do, but you can pass arguments like this

npm run script-a -- --logging

huangapple
  • 本文由 发表于 2023年6月5日 17:32:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76405103.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定