Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
11
Help us understand the problem. What is going on with this article?
@kudo_kk

npm-scripts 変数の使用方法

More than 3 years have 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について

11
Help us understand the problem. What is going on with this article?
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
kudo_kk
フロントエンドエンジニア

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
11
Help us understand the problem. What is going on with this article?