简体   繁体   English

Node.js&npm:如何创建自定义npm cli命令?

[英]Node.js & npm: How can I create custom npm cli commands?

Say for example that I quite often use npm list -g -depth 0 as command, and I'd like to alias it with npm listC or npm list -c1 . 例如,我经常使用npm list -g -depth 0作为命令,我想用npm listCnpm list -c1将其别名。

How do I do that? 我怎么做?

You can use npm scripts to create shortcuts for custom commands. 您可以使用npm脚本为自定义命令创建快捷方式。

In your package.json you might have: 在你的package.json你可能有:

{
    "scripts": {
        "listC": "npm list -g depth 0"
    }
} 

And you could then run it with npm run listC . 然后你可以用npm run listC运行它。

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

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