1

Is it posible to reuse a variable of the config section?

...
"config": {
   "source": "Hello",
   "root": "$npm_package_config_source World"
}
...

I can do this in the scripts section but I don't know if it is possible in the config section or there is one approach to have incremental variables in order to avoid copy & paste...

1
  • It's not possible to reference a config var from inside the config object in the way that you are describing. You can only reference them from inside the scripts section of package.json. So if your config object is defined something like this: "config": {"source": "Hello", "root": "World"} and in your scripts section you have something like this: "scripts": { "say-hello": "echo $npm_package_config_source $npm_package_config_root"} - then running npm run say-hello will successfully log Hello World to your console. Commented May 9, 2018 at 10:03

1 Answer 1

1

I don't think you can "reuse a variable" because there're not quite a variable. JSON files use key = value data, so every key have an unique value (or function). If you "reuse" any of the keys, you would overwrite the 'older' key/value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.