0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

package.jsonでコマンド引数を渡す方法など

Last updated at Posted at 2023-10-12

基本文法

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!
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?