简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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