问题描述
我有一个看起来像这样的package.json:
I have a package.json that looks similar to this:
"scripts": {
"dev": "cross-env BABEL_ENV=client webpack --config webpack/client.development.js && yarn dev:stub-server | cross-env BABEL_ENV=server babel-node src/server/server.js",
"dev:stub-server": "./node_modules/.bin/robohydra ./stubs/robohydra-config.json -p 3100"
}
我在代码中添加了一些逻辑,以根据命令行参数更改dev:stub-server
的配置方式.因此,无论何时运行以下命令,我都会得到期望的结果:
I added some logic in the code to change the way the dev:stub-server
is configured depending on a command line argument. So, whenever I run the following I get what I expect:
yarn dev:stub-server --results=4
$ ./node_modules/.bin/robohydra ./stubs/robohydra-config.json -p 3100 -- --results=4
如您所见,这些选项将转发到基础脚本,并且一切都会按预期进行.
As you can see, the options are forwarded to the underlying script and everything works as expected.
我的问题是我无法将--results
从yarn dev
命令传播到dev:stub-server
的正确位置.父脚本运行dev:stub-server
,但是该参数最后被转发到基础脚本,如下所示:
My problem is that I cannot have the --results
propagated from the yarn dev
command to dev:stub-server
in the correct position. The parent script runs dev:stub-server
but the argument is forwarded to the underlying script at the end as follows:
yarn dev --results=2
$ cross-env BABEL_ENV=client webpack --config webpack/client.development.js && yarn dev:stub-server | cross-env BABEL_ENV=server babel-node src/server/server.js --results=2
是否可以通过以下方法使上述工作正常进行?
Is there a way to make the above work as follows instead?
yarn dev --results=2
$ cross-env BABEL_ENV=client webpack --config webpack/client.development.js && yarn dev:stub-server --results=2 | cross-env BABEL_ENV=server babel-node src/server/server.js
提前谢谢!
推荐答案
纱线的 仅支持将args
附加到命令链的末尾,并且至少从2018年6月14日开始,没有任何方法可以覆盖它.
Yarn's run
only supports appending your args
to the end of the command chain, and at least as of date 2018-06-14, there isn't a way to override that.
过去我需要此功能时,我已经编写了自己的dev.js
脚本,该脚本由我的package.json
调用,并提取了参数变量.
When I've needed this in the past, I've cooked up my own dev.js
script that was called by my package.json
, and pulled args out environment variables.
这篇关于传递命令行-Yarn中子脚本的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!