When installing packages in npm, why do we need to add --save-dev
at the end?
Example:
npm install gulp-angular-templatecache --save-dev
From the documentation online (https://docs.npmjs.com/cli/install), it says "package will appear in your devDependencies
." What is that mean? Is that mean, if I don't put --save-dev
it will install on different directory?
In the package.json
file, it will automatically add the gulp-angular-templatecache
module to the devDependencies
object within the JSON after installing it locally in your application under node_modules
like normal. The only difference is the fact that it edits the package.json
file to remember that devDependency. It installs in the same location either way. So after running that, your package.json
will look like this as of now:
{
...
"devDependencies": {
...
"gulp-angular-templatecache": "^1.5.0"
},
...
}
package.json has two places to store dependency information: the "dependencies" object and the "devDependencies" object.
When you install an app and run "npm install" it pulls down both the dependencies and the devDependencies. However, if you do "npm install --production" it pulls down ONLY the dependencies, NOT the devDependencies.
The idea is that devDependencies are for things like test runners and assertion libraries; stuff you need while developing, but not stuff you need when you've actually deployed the app to production.