npm - Notes
10 Jun 2019dependencies vs. development dependencies
install package as dependency:
$ npm install --save <package>
install package as development dependency:
$ npm install --save-dev <package>
dependencies:
- added to
dependencies
section of package.json - application cannot run without it
-
transitive dependencies are installed
dependencies of your dependencies are installed recursively when you run
npm install
.
development dependencies:
- added to
devDependencies
section of package.json - packages are used in development environment only (say, Babel or Flow)
-
transitive development dependencies are not installed
that is if you install some package
foo
and it has its own development dependencies, they are not installed when you runnpm install
.
peer dependencies
- https://lexi-lambda.github.io/blog/2016/08/24/understanding-the-npm-dependency-model/
- https://stackoverflow.com/a/34645112/3632318
- https://blog.angularindepth.com/npm-peer-dependencies-f843f3ac4e7f
https://stackoverflow.com/a/34645112/3632318
peer dependencies tell npm:
I need this package, but I need the version that is part of the project, not some version private to my module.
https://blog.angularindepth.com/npm-peer-dependencies-f843f3ac4e7f
By adding a package in peerDependencies you are saying:
- My code is compatible with this version of the package.
- If this package already exists in node_modules, do nothing.
- If this package doesn’t already exist in the node_modules directory or it is the wrong version, don’t add it. But, show a warning to the user that it wasn’t found.
don’t use peer dependencies if you are not npm package author - they are not automatically installed by npm (since version 3):
https://lexi-lambda.github.io/blog/2016/08/24/understanding-the-npm-dependency-model/
peer dependencies are not automatically installed unless a dependent package explicitly depends on the peer package itself