gpt4 book ai didi

npm - 将参数传递到npm脚本的中间

转载 作者:行者123 更新时间:2023-12-04 22:57:46 25 4
gpt4 key购买 nike

标题说明了一切。我希望能够将参数传递给npm脚本的中间,以便我可以执行以下操作。

$ npm run deploy -- <destination-path>

在package.json中
"scripts": {
"deploy": "robocopy dist <destination-path> /E /NP"
}

是否可以不使用环境变量或npm的配置变量?

最佳答案

对于Passing args into run-scripts #5518,似乎无法将参数传递到脚本的中间。

We are not going to support passing args into the middle of the script, sorry. If you really need this, write your test command using literally any of the command line parsers that anyone uses. (Minimist, dashdash, nopt, and commander all support this just fine.)



但是,可以使用 npm configuration block has been documented here替代此方法。然后,我的实现如下所示:
"name": "foo"
"config": { "destination" : "deploy" },
"scripts": { "deploy": "robocopy dist %npm_package_config_destination% /E /NP" }

然后,我可以在命令行和构建服务器上使用以下命令覆盖它:
npm run deploy --foo:destination=C:\path\to\deploy\dir

关于npm - 将参数传递到npm脚本的中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37869773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com