How to pass a command line argument to a nested script?

a 夏天 提交于 2019-11-29 08:37:56

Your scripts field should look like this:

{
    ...
    "takes-args": "somemodule",
    "calls-takes-args": "npm run takes-args --"
}

Notice the -- at the end of calls-takes-args.

Anything you pass after the -- is directly appended onto the script you are running. When you run npm run calls-takes-args -- -env dev, that is the equivalent of running npm run takes-args -env dev. Of course, that does not work.

If you add the -- to calls-takes-args, when you run npm run calls-takes-args -- -env dev, npm run runs npm run takes-args -- -env dev. Success!

If you don't pass any args to calls-takes-args, the trailing -- won't hurt.


Edit:

If you can't/don't want to modify your package.json, you can run

npm run calls-takes-args -- -- -env dev

That will run somemodule -env dev.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!