我们可以在npm脚本中实现占位符并使用npm命令替换它吗?

问题描述 投票:1回答:1

我有一个npm脚本

"scripts": {
"test:chrome": "set DEV_MODE=staging& npx testcafe \"chrome --start-fullscreen\" automation_suite/tests"
}

我想将DEV_MODE=staging替换为DEV_MODE=dev,而不是编写多个脚本。

类似

[npm run test:chrome --dev应将staging替换为dev并执行脚本

node.js npm testcafe npm-scripts
1个回答
0
投票

您可以编写一些具有默认值的命令,如果需要传递其他参数,则用户可以改写。样本:

"scripts": {
    "test:chrome": "export DEV_MODE=${DEV_MODE:-staging} && echo $DEV_MODE"
  },

Run:

$npm run test:chrome
#Output: staging

$DEV_MODE=dev npm run test:chrome
#Output: dev

这至少将简化您的书写方式。

© www.soinside.com 2019 - 2024. All rights reserved.