Help us understand the problem. What is going on with this article?

npm-scripts 変数の使用方法

More than 1 year has passed since last update.

フロントエンド開発環境であるnpmにおいて、npm-scriptsのみで完結したい時、package.json内において、変数を使用したいと考えると思います。しかし、変数の使用方法についての記述を見つけることができなかったので、投稿いたします。

変数の定義

config内で変数名(key)を設定

{
 "config": {
  "key": "value"
 },
 "scripts": {}
}

変数の使用

scripts内で$npm_package_config_keyとすると、展開される。

{
"scripts": {
  "scriptName": "command $npm_package_config_key"
 }
}

参考: npmの公式ページにおける、package.jsonについて

kudo_kk
フロントエンドエンジニア
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした