訪問通過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”


注意!

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



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