npm install 的 --save 选项是什么? [英] What is the --save option for npm install?
问题描述
我看到了一些命令所在的教程:
I saw some tutorial where the command was:
npm install --save
--save
选项是什么意思?
无法在 Google 上找到答案.
Not able to find the answer on Google.
推荐答案
更新 npm 5:
从 npm 5.0.0 开始,已安装的模块默认添加为依赖项,因此不再需要 --save
选项.其他保存选项仍然存在,并列在 npm install
文档中>.
As of npm 5.0.0, installed modules are added as a dependency by default, so the --save
option is no longer needed. The other save options still exist and are listed in the documentation for npm install
.
原答案:
在版本 5 之前,NPM 只是默认在 node_modules
下安装一个包.当您尝试为您的应用程序/模块安装依赖项时,您需要先安装它们,然后将它们(连同适当的版本号)添加到您的 package 的
.dependencies
部分.json
Before version 5, NPM simply installed a package under node_modules
by default. When you were trying to install dependencies for your app/module, you would need to first install them, and then add them (along with the appropriate version number) to the dependencies
section of your package.json
.
--save
选项指示 NPM 自动将包包含在 package.json
的 dependencies
部分中,从而节省您一个额外的步骤.
The --save
option instructed NPM to include the package inside of the dependencies
section of your package.json
automatically, thus saving you an additional step.
此外,还有补充选项 --save-dev
和 --save-optional
将包保存在 devDependencies
和optionalDependencies
,分别.这在安装仅用于开发的软件包时很有用,例如 grunt
或您的测试库.
In addition, there are the complementary options --save-dev
and --save-optional
which save the package under devDependencies
and optionalDependencies
, respectively. This is useful when installing development-only packages, like grunt
or your testing library.
这篇关于npm install 的 --save 选项是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!