[英]Difference between npm install --save and npm install --save-dev
Guys I know that using npm install -g
we can install the node modules/packages globally, but I am not sure about the options --save
and --save-dev
伙计们,我知道使用npm install -g
我们可以全局安装节点模块/包,但我不确定选项--save
和--save-dev
I have Googled it but still not clear about it.我已经谷歌了它,但仍然不清楚。 Please share your thoughts.请分享您的想法。
--save
adds the third-party package to the package's dependencies . --save
将第三方包添加到包的依赖项中。 It will be installed together with the package whenever someone runs npm install yourPackage
.每当有人运行npm install yourPackage
时,它将与包一起npm install yourPackage
。
--save-dev
adds the third-party package to the package's development dependencies . --save-dev
将第三方包添加到包的开发依赖项中。 It won't be installed when someone installs your package.当有人安装您的软件包时,它不会被安装。 It's typically only installed if someone clones your source repository and runs npm install
in it.它通常仅在有人克隆您的源存储库并在其中运行npm install
时才会npm install
。
Dev dependencies, as the same suggests, 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.两种类型的依赖项都存储在包的package.json
文件中。 --save
adds to dependencies
, --save-dev
adds to devDependencies
. --save
添加到dependencies
, --save-dev
添加到devDependencies
。 From the documentation :从文档:
devDependencies开发依赖
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 this case, it's best to map these additional items in a devDependencies object.在这种情况下,最好将这些附加项映射到 devDependencies 对象中。
These things will be installed when doing npm link or npm install from the root of a package, and can be managed like any other npm configuration param.这些东西将在从包的根目录执行 npm link 或 npm install 时安装,并且可以像任何其他 npm 配置参数一样进行管理。 See npm-config(7) for more on the topic.有关该主题的更多信息,请参阅 npm-config(7)。
For build steps that are not platform-specific, such as compiling CoffeeScript or other languages to JavaScript, use the prepublish script to do this, and make the required package a devDependency.对于非特定于平台的构建步骤,例如将 CoffeeScript 或其他语言编译为 JavaScript,请使用预发布脚本来执行此操作,并使所需的包成为 devDependency。
Edit: As of npm 5.0.0 the installed modules are added as a dependency by default, so the --save option is no longer needed.编辑:从npm 5.0.0 开始,安装的模块默认添加为依赖项,因此不再需要 --save 选项。
--save-dev
is used to save the package for development purpose. --save-dev
用于保存用于开发目的的包。 Example: unit tests, minification.示例:单元测试、缩小。--save
is used to save the package required for the application to run. --save
用于保存应用程序运行所需的包。--save-dev
will save npm modules in development dependencies in package.json ie it will save inside devDependencies object. --save-dev
将 npm 模块保存在 package.json 中的开发依赖项中,即它将保存在 devDependencies 对象中。--save
will save npm modules dependencies in package.json ie it will save inside dependencies object. --save
将在 package.json 中保存 npm 模块依赖项,即它将保存在依赖项对象中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.