npm install 与 update - 有什么区别? [英] npm install vs. update - what's the difference?

查看:34
本文介绍了npm install 与 update - 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

npm installnpm 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
  • 更新

另外:installupdate 默认以不同的方式处理 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 - 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆