What is the difference between the --save-dev
and --save
commands when installing the package via npm
?
Answer 1, authority 100%
-S, –save: The package will show up in your dependencies
-D, –save-dev: the package will show up in your devDependencies
For more information see npm-install
Answer 2, authority 69%
If you specify the –save flag, then when installing a package, its name and version will be written in the package.json file in the section dependencies .
If installed with the flag –save-dev , then the name and version will go to the devDependencies
section
Answer 3, authority 62%
In npm 6.5, you don’t have to write -save
or -s
, npm will add the installed package to you in “dependencies”: {}.
From the documentation https://docs.npmjs.com/cli/install :
-P
, --save-prod
: again will save in “dependencies”: {}. This is your production code and will be included in your final product. Add here only those libraries that will be used in the work of your final product (web pages for example).
-D
, --save-dev
: will save the package to “devDependencies”: {}. These are the packages that you use in the development process, LESS preprocessors, SASS, code validators, JShint Slint, JS preprocessors: Babel. These packages will not be included in the final product.
-O
, --save-optional
: The package will be added to “optionalDependencies”: {}. these packages can be used in production, but if they are not available or an error occurs while installing them, then npm will simply skip them and continue working.
--no-save
: Prevents the package from being saved to package.json.
+ Additional flags:
-E
, --save-exact
: will save the package version exactly as specified.
-B
, --save-bundle
: saves the bundle in “bundleDependencies”: {}.
Answer 4
If I remember correctly, when you add -dev
, then in addition to the package everything that it depends on is installed.
For example:
bower install jqueryvalidation --save-dev
Will supply jqueryvalidation and jquery. since how dependent on her. if you specify without -dev, then jquery will not be delivered.