I've just started using Grunt.js. It is pretty hard to set up and I am at the point of creating a package.json
file.
Following this tutorial, it says there are 3 ways to create a package.json
file.
The first is to do npm install grunt --save-dev
But what does --save-dev
means? I tried looking but it ends in vain.
For me the first answer appears a bit confusing, so to make it short and clean:
npm install <package_name>
saves any specified packages into dependencies by default. Additionally, you can control where and how they get saved with some additional flags:
npm install <package_name> --no-save
Prevents saving to dependencies.
npm install <package_name> ---save-dev
updates the devDependencies
in your package. These are only used for local testing and development.
You can read more at in the dcu
Documentation from npm for npm install <package-name> --save
and npm install <package-name> --save-dev
can be found here:
https://docs.npmjs.com/getting-started/using-a-package.json#the-save-and-save-dev-install-flags
A package.json
file declares metadata about the module you are developing. Both aforementioned commands modify this package.json
file. --save
will declare the installed package (in this case, grunt
) as a dependency for your module; --save-dev
will declare it as a dependency for development of your module.
Ask yourself: will the installed package be required for use of my module, or will it only be required for developing it?
To add on to Andreas' answer, you can install only the dependencies by using:
npm install --production
There are (at least) two types of package dependencies you can indicate in your package.json files:
Those packages that are required in order to use your module are listed under the "dependencies" property. Using npm you can add those dependencies to your package.json file this way:
npm install --save packageName
Those packages required in order to help develop your module are listed under the "devDependencies" property. These packages are not necessary for others to use the module, but if they want to help develop the module, these packages will be needed. Using npm you can add those devDependencies to your package.json file this way:
npm install --save-dev packageName
When you use the parameter "--save" your dependency will go inside the #1 below in package.json. When you use the parameter "--save-dev" your dependency will go inside the #2 below in package.json.
#1. "dependencies": these packages are required by your application in production.
#2. "devDependencies": these packages are only needed for development and testing
Source: Stackoverflow.com