我需要为npm和yarn编写通用脚本。
{
"scripts": {
"build:clean": "rim-raf dist",
"test:clean": "rim-raf coverage",
"clean": "npm run build:clean; npm run test:clean"
}
}
纱线的{
"scripts": {
"build:clean": "rim-raf dist",
"test:clean": "rim-raf coverage",
"clean": "yarn run build:clean; yarn run test:clean"
}
}
我通常会使用一些小技巧: $ _
{
"scripts": {
"build:clean": "rim-raf dist",
"test:clean": "rim-raf coverage",
"clean": "$_ run build:clean; $_ run test:clean"
}
}
但是有时无法正常工作。
存在某种合法的方法吗?
我发现我正在寻找solution。
答案 0 :(得分:4)
我认为我找到了最佳解决方案。
我在 npm env 中进行了搜索,并将其与 yarn env 进行了比较。
我找到了变量 $ npm_execpath ,其中包含所用软件包管理器的路径。 (对于Windows %npm_execpath%)
{
"scripts": {
"build:clean": "rim-raf dist",
"test:clean": "rim-raf coverage",
"clean": "$npm_execpath run build:clean; $npm_execpath run test:clean"
}
}
如果添加软件包cross-var,则脚本可在Linux,Windows和Mac上运行。
{
"scripts": {
"build:clean": "rim-raf dist",
"test:clean": "rim-raf coverage",
"clean": "cross-var $npm_execpath run build:clean; cross-var $npm_execpath run test:clean"
}
}
答案 1 :(得分:0)
您可以尝试以下第三方模块: