访问通过npm运行脚本发送的参数

[英]Accessing arguments sent via npm run-script


I run the command:

我运行以下命令:

npm run a_script --oki="odo"

How do I get the value of oki in my script? I'd like to use it for example: if(process.argv.oki === 'odo').

如何在脚本中获得oki的值?例如:if(process.argv)。冲电气= = =“辛癸酸甘油酯”)。

I tried:

我试着:

console.log(process.argv);

It doesn't show up there.

它不会出现在那里。

I read https://docs.npmjs.com/cli/run-script and it doesn't give an example.

我读了https://docs.npmjs.com/cli/run-script,它没有给出一个例子。

1 个解决方案

#1


2  

You just have to insert two dashes between the script name and the argument list for npm to pass them to your script.

只需在脚本名称和npm的参数列表之间插入两个破折号,就可以将它们传递给脚本。

e.g. npm run a_script -- --oki="odo"

例如npm运行a_script -- -oki=“odo”

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2016/11/10/7205493b8d04250ece395ce9a23603df.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告