澄清 npm install 的 --save 选项 [英] Clarification of the --save option for npm install
问题描述
初体验 node.js/npm.从我阅读的 npm-install 文档中:
First experiences with node.js/npm. From the npm-install docs I read:
npm install
采用 3 个独占的可选标志,用于保存或更新主 package.json
中的包版本:
npm install
takes 3 exclusive, optional flags which save or update the package version in your main package.json
:
--save
:包将出现在您的依赖项
中.
--save-dev
:包将出现在您的 devDependencies
中.
--save-dev
: Package will appear in your devDependencies
.
--save-optional
:包将出现在您的optionalDependencies
中.
但我无法理解它在实践中是如何工作的.例如,如果我运行以下命令:
But I can't understand how it works in practice. If, for example, I run the command:
npm install bower --save-dev
我希望在当前目录中找到一个 package.json
文件,其中 devDependencies
设置为 bower 的已安装版本,但我什么也没找到.
I'd expect to find a package.json
file in the current directory with devDependencies
set to the installed version of bower, instead I find nothing.
我在做什么/期望有什么问题吗?
Am I doing/expecting something wrong?
在 Ubuntu 12.04 x64 上使用 node v0.10.21、npm 1.3.12
Using node v0.10.21, npm 1.3.12 on Ubuntu 12.04 x64
推荐答案
npm
不会创建 package.json
为您,但它将为您创建必要的依赖项,只要 package.json
存在并且是合法的 JSON.
npm
won't create package.json
for you, but it will create the necessary dependencies for you as long as package.json
exists and is legal JSON.
像这样创建它
echo {} > package.json
然后,执行 npm i --savewhat
将按预期添加 whatever@~x.x.x
作为依赖项.文件需要在那里,并且是 JSON,就是这样.
Then, doing npm i --save whatever
will add whatever@~x.x.x
as a dependency as expected. The file needs to be there, and be JSON, that's it.
这篇关于澄清 npm install 的 --save 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!