--save 和 --save-dev 有什么区别? [英] What is the difference between --save and --save-dev?
问题描述
有什么区别:
npm install [package_name]
和:
npm install [package_name] --save
和:
npm install [package_name] --save-dev
这是什么意思?--save
和 -dev
关键字的真正作用是什么?
What does this mean? And what is really the effect of --save
and -dev
keywords?
推荐答案
--save
和 --save-dev
之间的区别可能不会立即引起注意在您自己的项目中尝试过它们.所以这里有几个例子...
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...
假设您正在构建一个使用 moment 的应用用于解析和显示日期的包.您的应用程序是一个调度程序,因此它确实需要此程序包才能运行,例如:没有它就无法运行.在这种情况下,您将使用
Let's 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
这将在您的 package.json 中创建一个新值
This would create a new value in your package.json
"dependencies": {
...
"moment": "^2.17.1"
}
在开发时,使用测试套件等工具确实很有帮助,可能需要 jasmine-核心 和karma.在这种情况下,您将使用
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
这也会在你的 package.json 中创建一个新值
This would also create a new value in your package.json
"devDependencies": {
...
"jasmine-core": "^2.5.2",
"karma": "^1.4.1",
}
您不需要测试套件以在其正常状态下运行应用程序,因此它是一个 --save-dev
类型的依赖项,仅此而已.你可以看到如果你不了解真正发生的事情,这有点难以想象.
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.
直接取自 NPM 文档 docs#dependencies
Taken directly from NPM docs docs#dependencies
依赖
依赖项在一个映射包名称的简单对象中指定到一个版本范围.版本范围是一个字符串,具有一个或更多以空格分隔的描述符.也可以识别依赖关系使用 tarball 或 git URL.
Dependencies are specified in a simple object that maps a package name to a version range. The version range is a string that has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.
请不要将测试工具或转译器放在您的依赖项中目的.请参阅下面的 devDependencies.
即使在文档中,它也要求您将 --save-dev
用于测试工具等模块.
Even in the docs, it asks you to use --save-dev
for modules such as test harnesses.
这篇关于--save 和 --save-dev 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!