简体   繁体   English

Node.js package.json定义与依赖项名称相同的脚本

[英]Nodejs package.json defining scripts with the same name as a dependency

I've seen a lot of package.json files where there are scripts that doesn't do anything but call a dependency with the same name. 我看过很多package.json文件,其中的脚本除了调用具有相同名称的依赖项外什么也不做。 For example : 例如 :

{
    "scripts": {
        "lint": "npm run tslint \"src/**/*.ts\"",
        "tslint": "tslint"
    },
    "devDependencies": {
        "tslint": "~4.4.2",
        "tslint-loader": "^3.3.0"
    }
}

Here we have the script tslint that just calls the dependency tslint . 在这里,我们有脚本tslint ,它仅调用依赖项tslint I guess that is some kind of a way to make the lint script shorter but how would it look like if there was no script called tslint . 我猜想这是使lint脚本更短的一种方法,但是如果没有名为tslint脚本,它tslint

I don't believe NPM has this kind of functionality built in. Yarn (the third-party NPM client built by Facebook, Google, Exponent and Tilde) on the other hand, does - you can just use yarn run and it will pick up the executable from your dependencies, even if you don't have a script for it defined in your package.json : 我不相信NPM具有内置的这种功能。另一方面, Yarn (由Facebook,Google,Exponent和Tilde构建的第三方NPM客户端)可以-您可以使用yarn run它将接起来即使您在package.json没有为脚本定义脚本,也可以使用依赖项中的可执行文件:

yarn run tslint
yarn run tslint "src/**/*.ts"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM