npm install 和 npm update 之间的实际区别是什么?我应该什么时候使用哪个?
What is the practical difference between npm install and npm update? When should I use which?
推荐答案npm install 的区别 和 npm update 处理 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 更新
另外:install 和 update 默认以不同的方式处理 devDependencies
Additionally: install and update by default handle devDependencies differently
- npm install 将 安装/更新 devDependencies,除非添加了 --production 标志
- npm update 将忽略 devDependencies,除非添加了 --dev 标志
- npm install will install/update devDependencies unless --production flag is added
- npm update will ignore devDependencies unless --dev flag is added
为什么要使用 npm install?
因为 npm install 除了处理 package.json 中的依赖项之外,还能做更多的事情.正如您在 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 将它们设置为 global(将它们放在 shell 的 PATH 中)
- 安装 git 标签描述的某些版本
- 从 git url 安装
- 使用 --force 强制重新安装
- manually install node-modules
- set them as global (which puts them in the shell's PATH) using npm install -g <name>
- install certain versions described by git tags
- install from a git url
- force a reinstall with --force
更多推荐
npm install 与 update
发布评论