Compiled a list of differences between different types of dependencies supported by NPM. If you are someone like who doesn't change package.json
often but needs something for a quick reference then the below table might be helpful.
Dimension | Direct | Dev | Peer | Optional | Bundled |
---|---|---|---|---|---|
Popular use-case | Using lodash functions on your page |
Using webpack to build your app |
Building libraries and plugins. react-dom could be a peer dependency for react |
Using packages which only work on certain platforms for e.g. fb-watchman which doesn't work on windows (till now) |
When you want to ship a package/module along with your npm-package and the package/module is not on the npm registry |
Required in production | Yes | No | Yes | Yes if available | Yes |
Required during development | Yes | Yes | Yes | Yes if available | Yes |
Name | dependencies | devDependencies | peerDependencies | optionalDependencies | bundledDependencies or bundleDepencies |
Specified as | Object | Object | Object | Object | Array |
Command | npm install <package-name@version> |
npm install <package-name@version> --save-dev |
NA | npm install <package-name@version> --save-optional |
NA |
<package-name@version>
can also be a git
url or a folder on disk. For more information, refer to npm install --help
.