npm运行脚本的命名参数 [英] named parameter to npm run script

查看:116
本文介绍了npm运行脚本的命名参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将命名参数传递给npm运行脚本,以便执行以下操作:

I would like to pass a named parameter to an npm run script so I can do something like the following:

"scripts":{
    "say-hello":"echo $greeting && ls"
 }

 npm run hello --greeting=hello

我希望将'hello'代替$ greeting变量,回显命令,然后执行ls(这显然是链接命令的简单示例)

I'd like it to then put 'hello' in place of the $greeting variable, echo the command and then do the ls (this is obviously just a simple example of a chained command)

推荐答案

刚刚发现这可行:

"scripts":{
  "say-hello" : "echo $npm_config_greeting && ls"
}

任何以 npm_config _ 开头的环境变量都将被解释为配置参数.例如,将 npm_config_foo = bar 放入您的环境会将 foo 配置参数设置为 bar .

Any environment variables that start with npm_config_ will be interpreted as a configuration parameter. For example, putting npm_config_foo=bar in your environment will set the foo configuration parameter to bar.

npm文档

这篇关于npm运行脚本的命名参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆