【问题标题】:How to pass an argument in command line to run the script for yarn如何在命令行中传递参数以运行纱线脚本
【发布时间】:2020-04-07 09:29:04
【问题描述】:

我对 JS 很陌生。我知道npm 允许您使用process.env.npm_config_key 在命令行中传递变量,例如

npm run --key="My Secret Passphrase" test:integration

但我如何使用yarn 做到这一点?

预计会这样:yarn run --key="My Secret Passphrase" test:integration

【问题讨论】:

  • yarn --key="My Secret Passphrase" test:integration 这应该可以工作
  • 但是如何替换我在函数中用来获取密钥的“process.env.npm_config_key”?

标签: javascript npm yarnpkg


【解决方案1】:

您可以使用标准环境变量:

在命令行上,

MY_KEY="My Secret Passphrase" yarn run test:integration

在代码中,阅读process.env.MY_KEY

【讨论】:

  • 不幸的是,这种方法不起作用。我尝试了两种方法:MY_KEY="My Secret Passphrase" yarn run test:integration VS yarn MY_KEY="My Secret Passphrase" run test:integration。不过,我将 process.env.MY_KEY 放在了我的代码中。收到错误“MY_KEY”不是内部或外部命令、可运行程序或批处理文件
  • 您是直接在终端中尝试,还是以其他方式尝试? yarn MY_KEY="My Secret Passphrase" run test:integration 不起作用
猜你喜欢
  • 2021-02-01
  • 2018-10-05
  • 1970-01-01
  • 1970-01-01
  • 2013-10-11
  • 2021-09-30
  • 2011-12-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多