简体   繁体   中英

Is npm install --save-dev gulp-uglify different to npm install gulp-uglify

I am confused about the npm install process. From what I understand there are some different options for me when installing modules:

  • -g option that stores the modules globally
  • --save-dev
  • no arguments.

Can someone explain what the differences are? Specifically when I do a -g (global) and another install locally does it get the modules from where I saved it globally?

Also what does it mean by "--save: Package will appear in your dependencies."

What dependencies is it talking about?

Okay. So the thing is:

  1. If you only want to install the dependency locally, then run: npm install gulp-uglify , and it will create a folder called node_modules, in which you will find the required module.
  2. If instead, you want to install the package globally, then you have to run: npm install -g gulp-uglify , that will allocate the package on your OS, and you will be able to use it anywhere (not only on that folder).
  3. The option --save-dev (that will be npm install --save-dev gulp-uglify ) will also update your package.json file and it will be added as a dev dependency, which is your app manifesto. That means, on that file you will have declared all the dependencies that you will need on your project, and they will be installed just by running npm install . In order to create the package.json file, you have to run npm init .

More info can be found here . Or this other post . Hope this helps!

-g puts the module in your global node_modules directory. These are available from any directory (hence global)

--save-dev updates your package.json file to include the module as a dev dependency. These are downloaded to your local node_modules folder for the directory.

No save argument updates your package.json file to include the module as a dependency. These are also downloaded to your local node_modules folder for the directory.

devDependencies and dependencies have implications when somebody wants to install your project (via npm install). For example, npm install will install all dependencies and devDependencies. npm install --production will not install devDependencies.

So you would use --save-dev when the node module you are importing is used for development purposes and not runtime (eg maybe jshint to do a build). Modules that are needed for running your application should not use the --save-dev switch.

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