我有一个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
并执行脚本
您可以编写一些具有默认值的命令,如果需要传递其他参数,则用户可以改写。样本:
"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
这至少将简化您的书写方式。