什么是npm命令来全局安装devDependencies?

时间:2013-08-06 21:08:53

标签: node.js install package global

我更喜欢键入一个简短的命令,比如npm install -g来设置项目的全局依赖项,比如node-sass和jshint,而不是手动输入npm install -g every single package。有没有npm-idiomatic方法呢?

2 个答案:

答案 0 :(得分:1)

You are using npm install -g <pkg> wrong here. -g indicates, that it's no project dependencies, than rather you global (PC wide).

Those plugins are no devDependencies, but CLI runners. What you want is npm install --save-dev every single package upon initialisation. When you need to install those dependencies again you'd just run npm install and include something like ./node_modules/.bin/jshint to your package.json scripts in order not to depend on the CLIs.

答案 1 :(得分:0)

我知道您不应该这样做,但是如果您仍然想要它,请更改您的全球位置以确保您拥有权限。安装 jq(下载它,或者 apt install jq)然后:

export NPM_CONFIG_PREFIX=~/npm-global
cat ./package.json | jq '.devDependencies | keys[] as $k | "\($k)@\(.[$k])"' | xargs -t npm install --global 

这将从 devDependencies 部分创建一个包和版本列表,将其通过管道传输到 xargs,并使用它们调用 npm install。

相关问题