“Npm install --global” and “--save” together?

独自空忆成欢 提交于 2021-02-17 19:19:06

问题


I was wondering if makes any sense to use in the npm install command the --global and the --save parameters all together. For example:

npm install gulp -g -s

As far as I know there is no package.json in the npm system folder, so I suppose the answer is "no", but I want to clear all doubt.


回答1:


The npm install command does not support installing a module both globally and save it to the package.json in one step.

There is, however, a way to install a module globally indirectly. The package.json supports a preinstall property like so:

"scripts": {
  "preinstall": "npm install -g gulp"
}

As soon as you execute npm install, gulp will be installed globally. Please note that your current user then needs permission to write to your global node module directory.



来源:https://stackoverflow.com/questions/38056275/npm-install-global-and-save-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!