简体   繁体   中英

Difference between npm install --save and npm install --save-dev

Guys I know that using npm install -g we can install the node modules/packages globally, but I am not sure about the options --save and --save-dev

I have Googled it but still not clear about it. Please share your thoughts.

--save adds the third-party package to the package's dependencies . It will be installed together with the package whenever someone runs npm install yourPackage .

--save-dev adds the third-party package to the package's development dependencies . It won't be installed when someone installs your package. It's typically only installed if someone clones your source repository and runs npm install in it.

Dev dependencies, as the same suggests, are those dependencies that are only needed for developing the package. That can include test runners, compilers, packagers, etc.

Both types of dependencies are stored in the package's package.json file. --save adds to dependencies , --save-dev adds to devDependencies . From the documentation :

devDependencies

If someone is planning on downloading and using your module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use.

In this case, it's best to map these additional items in a devDependencies object.

These things will be installed when doing npm link or npm install from the root of a package, and can be managed like any other npm configuration param. See npm-config(7) for more on the topic.

For build steps that are not platform-specific, such as compiling CoffeeScript or other languages to JavaScript, use the prepublish script to do this, and make the required package a devDependency.

Edit: As of npm 5.0.0 the installed modules are added as a dependency by default, so the --save option is no longer needed.

  • --save-dev is used to save the package for development purpose. Example: unit tests, minification.
  • --save is used to save the package required for the application to run.
  1. --save-dev will save npm modules in development dependencies in package.json ie it will save inside devDependencies object.
  2. --save will save npm modules dependencies in package.json ie it will save inside dependencies object.

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