如何通过 npm 脚本传递环境变量?
How do I pass through an envrionment variable via npm script?
这是我现在的 package.json
{
"dependencies": {
"cypress": "^6.8.0",
"cypress-tags": "^0.0.21",
"typescript": "^4.2.3"
},
"scripts": {
"cy:run": "./node_modules/.bin/cypress run",
"cy:dev": "CYPRESS_INCLUDE_TAGS=DEVELOP ./node_modules/.bin/cypress run"
}
}
当我 运行 cy:dev 我得到这个错误:
'CYPRESS_INCLUDE_TAGS' is not recognized as an internal or external command,
operable program or batch file.
但是,如果我复制并粘贴确切的脚本,然后 运行 直接在 CLI 中,它就可以正常工作。
有什么方法可以通过 NPM 脚本传递临时环境变量吗?
我认为这可以在 Mac/Linux 系统上运行,但我需要它才能跨平台运行。
设法通过使用 npm 包解决了这个问题。
{
"dependencies": {
"cross-env": "7.0.3",
"cypress": "6.8.0",
"cypress-tags": "0.0.21",
"typescript": "4.2.3"
},
"scripts": {
"cy:run": "cross-env CYPRESS_INCLUDE_EXCLUDE=IGNORE ./node_modules/.bin/cypress run",
"cy:dev": "cross-env CYPRESS_INCLUDE_TAGS=DEVELOP ./node_modules/.bin/cypress run"
}
}
这也适用于跨平台。
这是我现在的 package.json
{
"dependencies": {
"cypress": "^6.8.0",
"cypress-tags": "^0.0.21",
"typescript": "^4.2.3"
},
"scripts": {
"cy:run": "./node_modules/.bin/cypress run",
"cy:dev": "CYPRESS_INCLUDE_TAGS=DEVELOP ./node_modules/.bin/cypress run"
}
}
当我 运行 cy:dev 我得到这个错误:
'CYPRESS_INCLUDE_TAGS' is not recognized as an internal or external command,
operable program or batch file.
但是,如果我复制并粘贴确切的脚本,然后 运行 直接在 CLI 中,它就可以正常工作。
有什么方法可以通过 NPM 脚本传递临时环境变量吗?
我认为这可以在 Mac/Linux 系统上运行,但我需要它才能跨平台运行。
设法通过使用 npm 包解决了这个问题。
{
"dependencies": {
"cross-env": "7.0.3",
"cypress": "6.8.0",
"cypress-tags": "0.0.21",
"typescript": "4.2.3"
},
"scripts": {
"cy:run": "cross-env CYPRESS_INCLUDE_EXCLUDE=IGNORE ./node_modules/.bin/cypress run",
"cy:dev": "cross-env CYPRESS_INCLUDE_TAGS=DEVELOP ./node_modules/.bin/cypress run"
}
}
这也适用于跨平台。