npm+yarn+nvm+nrm

220 阅读2分钟

npm

我的npm配置

chromedriver_cdnurl=https://npm.taobao.org/mirrors/chromedriver/
operadriver_cdnurl=http://npm.taobao.org/mirrors/operadriver/
NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node/
NVM_IOJS_ORG_MIRROR=http://npm.taobao.org/mirrors/iojs/
PHANTOMJS_CDNURL=https://npm.taobao.org/dist/phantomjs/
SASS_BINARY_SITE=http://npm.taobao.org/mirrors/node-sass/
SQLITE3_BINARY_SITE=http://npm.taobao.org/mirrors/sqlite3/
PYTHON_MIRROR=http://npm.taobao.org/mirrors/python/
ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/
msvs_version=2017

版本

  • alpha:内测版
  • beta:公测版
  • rc:Release Candidate的缩写,也就是发布倒计时

依赖类型

  1. 「dependences」 代码运行时所需要的依赖,比如vue,vue-router
  2. 「devDependences」 开发依赖,就是那些只在开发过程中需要,而运行时不需要的依赖,比如babel,webpack
  3. 「peerDependences」 同伴依赖,它用来告知宿主环境需要什么依赖以及依赖的版本范围,如Vue组件库中需要依赖Vue
  4. 「optionalDependences」 可选依赖,这种依赖即便安装失败,Yarn也会认为整个依赖安装过程是成功的。
  5. 「bundledDependences」 打包依赖,在发布包时,这个数组里的包都会被打包到最终的发布包里

registry

registry是模块仓库提供了一个查询服务,也就是我们常说的源。比如官方的源它的查询服务网址是https:/registry.yarnpkg.com

npm对应的查询网址是https://registry.npmjs.org,通过加上/vue就能查询到所有vue的版本信息,加上/vue/2.6.10可以查询某个版本的具体信息

yarn

yarn的包遵循semver,即语义化版本。SemVer是一套语义化版本控制的约定,定义的格式为

X.Y.Z(主.次.修订)(major.minor.patch)

~3.1.4 >=3.1.4<3.2.0

~3.1 >=3.1<3.2.0

~3 >=3.0.0<4.0.0

^3.1.4 >=3.1.4<4.0.0

^0.4.2 >=0.4.2<0.5.0

缓存:yarn cache dir可以查看缓存目录

nvm

管理node版本,所有通过nvm安装的node都会在C:\Users\yunbo\AppData\Roaming\nvm\v15.0.0 这个目录下找到,其中v15.0.0表示node版本。

安装了nvm的系统,如果出现已安装了某个程序但是找不到命令,很有可能是当前nvm使用的node版本不对,比如:

$ nvm use 8.12.0 32 // 使用 32 位的 8.12.0 node版本
Now using node v8.12.0 (32-bit)
$ vue -V
bash: vue: command not found
$ nvm use 10.16.0
Now using node v10.16.0 (64-bit)
$ vue -V
@vue/cli 4.0.5
$ nvm use 12.15.0
Now using node v12.15.0 (64-bit)
$ vue -V
bash: /c/Program Files/nodejs/vue: No such file or directory

nrm(nrm registry manager)

npm的镜像源管理工具,有时候国外资源太慢,使用这个就可以快速地在npm源间切换

直接通过npm全局安装nrmnpm install -g nrm

使用命令

$ nrm ls
  npm -------- https://registry.npmjs.org/
  yarn ------- https://registry.yarnpkg.com/
  cnpm ------- http://r.cnpmjs.org/
  taobao ----- https://registry.npm.taobao.org/
  nj --------- https://registry.nodejitsu.com/
  npmMirror -- https://skimdb.npmjs.com/registry/
  edunpm ----- http://registry.enpmjs.org/
* weier ------ http://47.99.38.237:9001/
$ nrm use taobao
   Registry has been set to: https://registry.npm.taobao.org/

npx

npx是安装npm时买一送一的结果。

zhuanlan.zhihu.com/p/27840803