npm / yarn 配置镜像、使用方法

npm 默认 registry:https://registry.npmjs.org/

 npm中文文档:https://www.npmjs.cn 

 淘宝 NPM 镜像:https://npm.taobao.org 

 CNPM:https://cnpmjs.org 

永久使用:

  npm config set registry URL (URL 即为需要设置的镜像站点地址)

 

  npm config set registry https://registry.npm.taobao.org --global  (淘宝镜像)

  npm config set disturl https://npm.taobao.org/dist --global  (Node镜像)

 

  npm config get registry 返回 https://registry.npm.taobao.org 即设置成功

  npm config get disturl 返回 https://npm.taobao.org/dist 即设置成功

 

临时使用:

  npm install [pkg] --registry=https://registry.npm.taobao.org

   例如: npm install cnpm -g --registry=https://registry.npm.taobao.org

 

使用 cnpm:

  npm install cnpm -g

  React Native 官网 搭建开发环境 不建议使用 cnpm

 

npm 命令缩写:

  -v: --version

  -g: --global

  -reg: --registry

  -S: --save

  -D: --save-dev

 

安装yarn:

npm install -g yarn

 

设置 yarn 镜像源:

yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global

 

yarn 使用方法:

  • Installing all the dependencies 安装依赖
    yarn
    yarn install

     

  • Adding a dependency 添加依赖
    yarn add [package]
    yarn add [package]@[version]
    yarn add [package]@[tag]

     

  • Adding a dependency to different categories of dependencies 添加依赖到不同依赖项中
    yarn add [package] --dev  # dev dependencies
    yarn add [package] --peer # peer dependencies

     

  • Upgrading a dependency 更新依赖
    yarn up [package]
    yarn up [package]@[version]
    yarn up [package]@[tag]

     

  • Removing a dependency 移除依赖
    yarn remove [package]

     

  • Upgrading Yarn itself 升级 yarn
    yarn set version latest
    yarn set version from sources

     

  • Accessing the list of commands 访问命令列表
    yarn help

     

  • Starting a new project 初始化项目
    yarn init

     

 

 

 
posted @ 2019-08-16 19:25  果冻丨小布丁  阅读(1939)  评论(0编辑  收藏  举报