npm安装与更新-有什么区别? [英] npm install vs. update - what's the difference?
问题描述
npm install
和npm update
之间的实际区别是什么?我什么时候应该使用哪个?
What is the practical difference between npm install
and npm update
? When should I use which?
推荐答案
npm install 和 npm更新处理 package.json 中指定的软件包版本:
The difference between npm install and npm update handling of package versions specified in package.json:
{
"name": "my-project",
"version": "1.0", // install update
"dependencies": { // ------------------
"already-installed-versionless-module": "*", // ignores "1.0" -> "1.1"
"already-installed-semver-module": "^1.4.3" // ignores "1.4.3" -> "1.5.2"
"already-installed-versioned-module": "3.4.1" // ignores ignores
"not-yet-installed-versionless-module": "*", // installs installs
"not-yet-installed-semver-module": "^4.2.1" // installs installs
"not-yet-installed-versioned-module": "2.7.8" // installs installs
}
}
摘要:唯一的不同是一个已经安装的具有模糊版本控制的模块 ...
Summary: The only big difference is that an already installed module with fuzzy versioning ...
- 被
npm install
忽略
- 由
npm update
更新
- gets ignored by
npm install
- gets updated by
npm update
此外:默认情况下,install
和update
对devDependencies的处理方式不同
Additionally: install
and update
by default handle devDependencies differently
-
除非添加
-
npm install
将安装/更新 devDependencies
除非添加 -
npm update
将忽略 devDependencies
--production
标志,否则--dev
标志,否则npm install
will install/update devDependencies unless--production
flag is addednpm update
will ignore devDependencies unless--dev
flag is added
为什么要完全使用npm install
?
Why use npm install
at all?
因为在处理package.json
中的依赖项时,npm install
的作用更大.
如您在 npm install 中所见,您可以...
Because npm install
does more when you look besides handling your dependencies in package.json
.
As you can see in npm install you can ...
- 手动安装节点模块
- 使用
npm install -g <name>
将它们设置为 global (将它们放入外壳的 - 安装git标签描述的某些版本
- 从git网址安装
- 使用
--force
强制重新安装
PATH
中)
- manually install node-modules
- set them as global (which puts them in the shell's
PATH
) usingnpm install -g <name>
- install certain versions described by git tags
- install from a git url
- force a reinstall with
--force
这篇关于npm安装与更新-有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!