node.js -save-dev 在 npm install grunt --save-dev 中是什么意思
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19223051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does -save-dev mean in npm install grunt --save-dev
提问by Vennsoh
I've just started using Grunt.js. It is pretty hard to set up and I am at the point of creating a package.jsonfile.
我刚刚开始使用Grunt.js。设置起来非常困难,我正在创建一个package.json文件。
Following this tutorial, it says there are 3 ways to create a package.jsonfile.
按照本教程,它说有 3 种方法可以创建package.json文件。
The first is to do npm install grunt --save-dev
第一个是做 npm install grunt --save-dev
But what does --save-devmeans?I tried looking but it ends in vain.
但是是什么--save-dev意思呢?我试图寻找,但它以徒劳的方式结束。
回答by Andreas Hultgren
--save-dev: Package will appear in your devDependencies.
--save-dev:包将出现在您的 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).
换句话说,当你运行时npm install,你的项目的 devDependencies 将被安装,但你的应用所依赖的任何包的 devDependencies 都不会被安装;此外,将您的应用程序作为依赖项的其他应用程序不需要安装您的 devDependencies。只有在开发应用程序时才需要这些模块(例如 grunt、mocha 等)。
According to the package.json docs
Edit: Attempt at visualising what npm installdoes:
编辑:尝试可视化做什么npm install:
- yourproject
- dependency installed
- dependency installed
- dependency installed
devDependency NOT installed
devDependency NOT installed
- dependency installed
- devDependency installed
- dependency installed
devDependency NOT installed
- dependency installed
- 你的项目
- 已安装依赖项
- 已安装依赖项
- 已安装依赖项
未安装 devDependency
未安装 devDependency
- 已安装依赖项
- 已安装 devDependency
- 已安装依赖项
未安装 devDependency
- 已安装依赖项
回答by Lonnie Best
There are (at least) two types of package dependencies you can indicate in your package.json files:
您可以在 package.json 文件中指明(至少)两种类型的包依赖项:
Those packages that are required in order to useyour module are listed under the "dependencies" property. Using npm you can add those dependencies to your package.json file this way:
npm install --save packageNameThose packages required in order to help developyour 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
使用模块所需的那些包列在“dependencies”属性下。使用 npm,您可以通过以下方式将这些依赖项添加到您的 package.json 文件中:
npm install --save packageName帮助开发模块所需的那些包列在“devDependencies”属性下。这些包对于其他人使用模块不是必需的,但是如果他们想帮助开发模块,则需要这些包。使用 npm,您可以通过以下方式将这些 devDependencies 添加到您的 package.json 文件中:
npm install --save-dev packageName
回答by machinehead115
To add on to Andreas' answer, you can install only the dependencies by using:
要添加 Andreas 的答案,您可以使用以下命令仅安装依赖项:
npm install --production
回答by Niko Kovacevic
Documentation from npm for npm install <package-name> --saveand npm install <package-name> --save-devcan be found here:
从NPM的文件npm install <package-name> --save和npm install <package-name> --save-dev可以在这里找到:
https://docs.npmjs.com/getting-started/using-a-package.json#the-save-and-save-dev-install-flags
https://docs.npmjs.com/getting-started/using-a-package.json#the-save-and-save-dev-install-flags
A package.jsonfile declares metadata about the module you are developing. Both aforementioned commands modify this package.jsonfile. --savewill declare the installed package (in this case, grunt) as a dependency for your module; --save-devwill declare it as a dependency for development of your module.
一个package.json文件声明你正在开发模块的元数据。上述两个命令都会修改此package.json文件。--save将已安装的包(在本例中为grunt)声明为您的模块的依赖项;--save-dev将其声明为模块开发的依赖项。
Ask yourself: will the installed package be required for use of my module, or will it only be required for developing it?
问问自己:安装的包是使用我的模块所必需的,还是仅用于开发它?
回答by Sathesh
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.
当您使用参数“--save”时,您的依赖项将位于 package.json 中的 #1 中。当您使用参数“--save-dev”时,您的依赖项将位于 package.json 中的以下 #2 中。
#1. "dependencies": these packages are required by your application in production.
#1. “依赖项”:您的应用程序在生产中需要这些包。
#2. "devDependencies": these packages are only needed for development and testing
#2. “devDependencies”:这些包只用于开发和测试
回答by AnnaKlein
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>默认情况下将任何指定的包保存到依赖项中。此外,您可以使用一些额外的标志来控制它们的保存位置和方式:
npm install <package_name> --no-savePrevents saving to dependencies.
npm install <package_name> --no-save防止保存到依赖项。
npm install <package_name> ---save-devupdates the devDependenciesin your package. These are only used for local testing and development.
npm install <package_name> ---save-dev更新devDependencies包中的 。这些仅用于本地测试和开发。
You can read more at in the dcu
您可以在 dcu 中阅读更多内容

