What is the difference between:
npm install [package_name] --save
and
npm install [package_name] --save-dev
What does this mean?
What is the difference between:
npm install [package_name] --save
and
npm install [package_name] --save-dev
What does this mean?
You generally don't want to bloat production package with things that you only intend to use for development purposes. So use --save-dev (or -D) option to separate those packages such as watchers(nodemon), unit test frameworks(jest, jasmine, mocha, chai etc.etc.)
Any other library packages that are must for your app to function need to be installed using --save (or -S)
If you open the package.json file then you will see these entries listed under two different sections:
As suggested by @andreas-hultgren in this answer and according to the npm docs:
However, for webapp development, Yeoman (a scaffolding tool that installs a peer-reviewed, pre-written package.json file amongst other things) places all packages in devDependencies and nothing in dependencies, so it appears that the use of
--save-dev
is a safe bet in webapp development, at least.I want to add some my ideas as
I think all differents will appear when someone use your codes instead of using by yourself
For example, you write a HTTP library called
node's request
In your library,
you used lodash to handle string and object, without lodash, your codes cannot run
If someone use your HTTP library as a part of his codes. Your codes will be compiled with his.
your codes need lodash, So you need put in
dependencies
to compileIf you write a project like
monaco-editor
, which is a web editor,you have bundle all your codes and your
product env library
using webpack, when build completed, only have amonaco-min.js
So someone don't case whether
--save
or--save-dependencies
, only he need ismonaco-min.js
Summary:
If someone want to compile your codes (use as library), put
lodash
which used by your codes intodependencies
If someone want add more feature to your codes, he need
unit test
andcompiler
, put these intodev-dependencies
--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.