首页 > 解决方案 > 将 npm_config_variable 传递给脚本

问题描述

我的 package.json 中有这个 npm 脚本

"scripts":{
    "test:file":"react-scripts test --coverage MyFileName --collectCoverageFrom=src/app/MyFileName.jsx"
}

我想通过 npm 命令传递我的文件名,例如npm run test:file --file MyFileName,我希望将我的脚本更改为如下所示,

"scripts":{
    "test:file":"react-scripts test --coverage $npm_config_file --collectCoverageFrom=src/app/$npm_config_file.jsx"
}

目前,只有第一个$npm_config_file被成功插入,而作为路径名一部分的第二个不起作用。

有人可以建议我如何更改脚本吗?

标签: reactjspackage.jsonreact-testing-library

解决方案


推荐阅读