Vennsoh
Vennsoh

Reputation: 5001

What does --save-dev (or -D) mean in npm install grunt --save-dev?

I've just started using Grunt. 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

The first method is to navigate to the project directory via command-line(Terminal) and install grunt using npm : sudo npm install grunt –save-dev. After the install, you can use grunt-init task to automatically generate a project-specific package.json file.

But what does --save-dev (short flag -D) mean? I tried looking but it ends in vain.

Upvotes: 313

Views: 133627

Answers (8)

Andreas Hultgren
Andreas Hultgren

Reputation: 14953

--save-dev: Package will appear in your devDependencies.

According to the npm install docs.

If someone is planning on downloading and using your module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use.

In other words, when you run npm install, your project's devDependencies will be installed, but the devDependencies for any packages that your app depends on will not be installed; further, other apps having your app as a dependency need not install your devDependencies. Such modules should only be needed when developing the app (eg grunt, mocha etc).

According to the package.json docs

Attempt at visualising what npm install does:

  • yourproject
    • dependency installed
      • dependency installed
        • dependency installed
        • devDependency NOT installed
      • devDependency NOT installed
    • devDependency installed
      • dependency installed
      • devDependency NOT installed

Upvotes: 344

BenKoshy
BenKoshy

Reputation: 35731

Use only when developing

  • --save-dev means omit in production environments, use only in development environments (smaller, and probably faster).

Upvotes: 2

Partha Kumar Bagchi
Partha Kumar Bagchi

Reputation: 121

–save

The package installed is core dependency.

–save-dev

The package installed is not a core rather development dependency.

Upvotes: 3

Sathesh
Sathesh

Reputation: 6428

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

Upvotes: 14

machinehead115
machinehead115

Reputation: 1657

To add on to Andreas' answer, you can install only the dependencies by using:

npm install --production

Upvotes: 36

Anna Klein
Anna Klein

Reputation: 2181

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

Upvotes: 5

Lonnie Best
Lonnie Best

Reputation: 11452

There are (at least) two types of package dependencies you can indicate in your package.json files:

  1. 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
    
  2. 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
    

Upvotes: 112

Niko
Niko

Reputation: 707

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?

Upvotes: 7

Related Questions