What is the difference between --save and --save-dev?
What is the difference between --save and --save-dev?
What is the difference between:
npm install [package_name]
and:
npm install [package_name] --save
and:
npm install [package_name] --save-dev
What does this mean? And what is really the effect of --save
and -dev
keywords?
--save-dev
is used to save the package for development purpose. Example: unit tests, minification..--save
is used to save the package required for the application to run.
The difference between --save
and --save-dev
may not be immediately noticeable if you have tried them both on your own projects. So here are a few examples...
Lets say you were building an app that used the moment package to parse and display dates. Your app is a scheduler so it really needs this package to run, as in: cannot run without it. In this case you would use
npm install moment --save
This would create a new value in your package.json
"dependencies": {
...
"moment": "^2.17.1"
}
When you are developing, it really helps to use tools such as test suites and may need jasmine-core and karma. In this case you would use
npm install jasmine-core --save-dev
npm install karma --save-dev
This would also create a new value in your package.json
"devDependencies": {
...
"jasmine-core": "^2.5.2",
"karma": "^1.4.1",
}
You do not need the test suite to run the app in its normal state, so it is a --save-dev
type dependency, nothing more. You can see how if you do not understand what is really happening, it is a bit hard to imagine.
Taken directly from NPM docs docs#dependencies
Dependencies
Dependencies are specified in a simple object that maps a package name to a version range. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.
Please do not put test harnesses or transpilers in your dependencies object. See devDependencies, below.
Even in the docs, it asks you to use --save-dev for modules such as test harnesses.
I hope this helps and is clear.
By default, NPM simply installs a package under node_modules. When you're trying to install dependencies for your app/module, you would need to first install them, and then add them to the dependencies
section of your package.json
.
--save-dev
adds the third-party package to the package's development dependencies. It won't be installed when someone runs npm install
directly to install your package. It's typically only installed if someone clones your source repository first and then runs npm install
in it.
--save
adds the third-party package to the package's dependencies. It will be installed together with the package whenever someone runs npm install package
.
Dev dependencies are those dependencies that are only needed for developing the package. That can include test runners, compilers, packagers, etc. Both types of dependencies are stored in the package's package.json
file. --save
adds to dependencies
, --save-dev
adds to devDependencies
npm install documentation can be referred here.
--
Please note that --save
is now the default option, since NPM 5. Therefore, it is not explicitly needed anymore. It is possible to run npm install
without the --save
to achieve the same result.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2020-01-21 RedGate support tickets
2019-01-21 Autofac Getting Started(默认的构造函数注入)
2019-01-21 Autofac Controlling Scope and Lifetime
2019-01-21 Autofac register and resolve
2019-01-21 What's the difference between UTF-8 and UTF-8 without BOM?
2016-01-21 Finalization