独立于操作系统访问 package.json 中的变量 [英] OS independent access to variables in package.json
本文介绍了独立于操作系统访问 package.json 中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要访问 npm 脚本中的变量,您可以在 package.json
中执行类似的操作:
To access a variable in npm scripts you would do something like this in your package.json
:
"scripts": {
"preinstall": "echo ${npm_package_name}"
}
问题是它只适用于 Unix,而不是 Windows,你必须使用 %npm_package_name%
.
The problem is that works only in Unix, not Windows, where you have to use %npm_package_name%
.
有没有办法让这个操作系统独立?如果 npm 可以在调用命令之前进行这样的变量扩展,那就太好了.
Is there a way to do this OS independent? It will be good if npm could do such a variable expansion, before invoking the command.
推荐答案
要使其跨平台,请使用 cross-var
:
To make it cross-platform, use cross-var
:
"scripts": {
"preinstall": "cross-var echo ${npm_package_name}"
}
这篇关于独立于操作系统访问 package.json 中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文