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

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

问题描述

npm installnpm 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

此外:默认情况下,installupdate对devDependencies的处理方式不同

Additionally: install and update by default handle devDependencies differently

    除非添加--production标志,否则
  • npm install安装/更新 devDependencies
  • 除非添加--dev标志,否则
  • npm update忽略 devDependencies
  • npm install will install/update devDependencies unless --production flag is added
  • npm 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 (将它们放入外壳的PATH中)
  • 安装git标签描述的某些版本
  • 从git网址安装
  • 使用--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安装与更新-有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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