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

Source: Internet
Author: User

Difference between -- save-dev and -- save when npm install
Description of two fields in package. json

I have been using the npm package manager. I have made some analysis on the differences between npm install module -- save-dev and npm install module -- save:

Dependencies

The dependencies attribute is declared in a simple object to control the package name within a certain version range. The version range is a string and can be separated by one or more spaces. Dependencied can also be specified as a package address or a git URL address.

Do not write the test tool or transpilers escape tool (babel, webpack, gulp, postcss...) into dependencies. (These should be written to devDependencies) configuration, because npm will download dependencies in dependencies when installing the package in other projects.

DevDependencies

If your package is dependent on or installed by others, npm install in the main project of the other party will not install the npm package in devDependencies in the dependency package, therefore, if some packages that your project depends on do not have to be installed when using this project, place the packages in devDependencies.

* ** Overall function comparison ****

Npm install module:

  • The module package is installed in the node_modules directory.
  • Package. json is not modified
  • When the npm install command is run later, the module package is not automatically installed.

Npm install module -- save

  • The module package is installed in the node_modules directory.
  • The package. json is modified to add the module name and version number to the dependencies section.
  • When you run the npm install command, the module package is automatically installed.
  • When you run npm install -- production or specify the NODE_ENV variable value as production, the module is automatically installed in the node_modules directory, that is, the package is installed when the online environment is running.

Npm install module -- save-dev

  • The module package is installed in the node_modules directory.
  • The package. json is modified to add the module name and version number to the devDependencies section.
  • When you run the npm install command, the module package is automatically installed.
  • When you run npm install -- production or specify the NODE_ENV variable value as production, msbuild will not be automatically installed into the node_modules directory, that is, the online environment will not be installed.

First, -- save and -- save-dev save the steps for manually modifying the package. json file. Some of our packaging tools and non-project dependencies are stored in devDependencies.

This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151499.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.