基本文法
package.json
{
"scripts": {
"script_name": "echo Hello ${npm_config_xxx}!"
}
}
terminal
npm run script_name --xxx=value
output
Hello value!
example
package.json
{
"scripts": {
"example": "echo Hello ${npm_config_name}!"
}
}
terminal
npm run example --name=jun01t
output
Hello jun01t!
##when multiple params
--params1=value1 --params2=value2
{
"scripts": {
"example": "echo Hello ${npm_config_params1}${npm_config_params2}!"
}
}
terminal
npm run example --param1=value1 --param2=value2
output
Hello value1value2!
when set params other script
package.json
{
"scripts": {
"example": "echo Hello ${npm_config_params1}${npm_config_params2}!",
"run_example":"npm run example --params1=${npm_config_params1} --params2=${npm_config_params2}"
}
}
command line
npm run run_example --params1=value1 --params2=value2
output
Hello value1value2!
appendix
{
"scripts": {
"parent": "echo Hello $(npm run -s child)!"
"child":"echo World"
}
}
terminal
npm run parent
output
Hello World!