问题描述
我正在构建package.json并使用"npm run"运行一些脚本,确切地说, https://docs.npmjs.com/misc/scripts .
I am building a package.json and use "npm run" to run some scripts, to be exactly, https://docs.npmjs.com/misc/scripts.
我的脚本需要扩展一些环境变量,我想使其跨平台兼容.例如,我的脚本会说
My script would need to expand some environment variables and I want to make it cross platform compatible. For example, my script would say
"scripts": {
"build": "md %npm_package_version%\helloworld"
}
但是由于环境变量的扩展,它当前正在Windows上运行. Linux将使用md $npm_package_version\helloworld
.
But it's currently running on Windows because the expansion of environment variables. Linux would use md $npm_package_version\helloworld
.
npm
是否带有转换环境变量扩展的机制,以便它可以跨平台工作?
Does npm
comes with a mechanism to convert environment variables expansion so that it works across platforms?
推荐答案
要使其跨平台,请使用 cross-var
:
To make it cross-platform, use cross-var
:
"scripts": {
"build": "cross-var md %npm_package_version%\helloworld"
}
这篇关于在跨平台的npm脚本中使用环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!