2016-04-27 59 views
3

说例如我经常使用npm list -g -depth 0作为命令,并且我想用npm listCnpm list -c1来替代它。Node.js&npm:如何创建自定义npm cli命令?

我该怎么做?

+0

除了下面duncanhall给出的答案之外,这里有一篇博客文章,当我开始使用NPM脚本时,发现它很有用 - 它们比您想象的要灵活得多:http://blog.keithcirkel.co。 uk/how-to-use-npm-as-a-build-tool/ –

回答

9

您可以使用npm scripts为自定义命令创建快捷方式。

在你package.json你可能有:

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

然后你可以用npm run listC运行它。

+2

'npm run listC'也可以工作 - 少少击键! –