In a node project I found 2 kind of dependencies:
"dependencies": {
"axios": "0.9.1",
"express": "4.13.4",
"lodash": "4.6.1",
"react": "^0.14.7",
"react-dom": "^0.14.7",
"react-redux": "^4.4.0",
"react-router": "^2.0.0",
"redux": "^3.3.1"
},
"devDependencies": {
"babel-core": "^6.5.2"
}
I know the author install it via npm install babel-core --save -dev
but what is that for? when you push your code, the devDependencies
module is still there.
The difference between these two, is that devDependencies are modules which are only required during development, while dependencies are modules which are also required at runtime. To save a dependency as a devDependency on installation we need to do an npm install --save-dev , instead of just an npm install --save.
NPM installs devDependencies within the package. json file. The 'npm install' command should add all the dependencies and devDependencies automatically during installation. If you need to add specific devDependencies to your project, you can use this command- 'npm install --save-dev'.
devDependencies: This property contains the names and versions of the node modules which are required only for development purposes like ESLint, JEST, babel etc. To install a node module as devDependency: npm install --save-dev [npm package name]
The dependencies value is used to specify any other modules that a given module (represented by the package. json ) requires to work. When you run npm install from the root folder of a given module, it will install any modules listed in that dependencies object.
I wrote an article about this however it was taken down.
Snippets from the article:
mod-a
dev-dependents:
- mod-b
dependents:
- mod-c
mod-d
dev-dependents:
- mod-e
dependents:
- mod-a
----
npm install mod-d
installed modules:
- mod-d
- mod-a
- mod-c
----
checkout the mod-d code repository
npm install
installed modules:
- mod-a
- mod-c
- mod-e
If you are publishing to npm, then it is important that you use the correct flag for the correct modules. If it is something that your npm module needs to function, then use the "--save" flag to save the module as a dependency. If it is something that your module doesn't need to function but it is needed for testing, then use the "--save-dev" flag.
# For dependent modules
npm install dependent-module --save
# For dev-dependent modules
npm install development-module --save-dev
If you aren't publishing to npm, it technically doesn't matter which flag you use. However, I find it a good practice to use the "--save" flag for modules that introduce non-standard code into the source files. Then use the "--sav-dev" flag for modules that are required for your compiler to function.
# For modules that introduce non-standard source code
npm install source-module --save
# For modules that your compiler needs to function
npm install compiler-module --save-dev
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With