包的管理npm、cnpm、yarn

279 阅读1分钟

包的管理

就是管理包文件的:帮助所有人的包文件的发布,安装,依赖(如果你要下载a包,但是npm发现你的a包,需要依赖b包,所有会自动帮你下载b包)

常见的包管理:npm/cnpm/yarn

npm

  • npm 是包的管理工具

  • npm 是一个网站 npmjs.org ,主要管理一些第三方的包

配置npm镜像
  # 配置淘宝镜像
  npm config set registry https://registry.npm.taobao.org

  # 查看镜像
  npm config get registry 

  # 安装nrm管理镜像
  npm i nrm -g 

  # 查看所有的镜像
  nrm ls|list 

  # 设置使用镜像  
  nrm use 镜像名称  

npm 常用命令
  # 查看版本
  npm -V 

  # 初始化项目 
  npm init -y

  # 根据package.json安装依赖包 
  npm install  简写 npm i

  # 安装包
  npm install 包的名称 -global(-g)|-save(-S)|-dev(-D)

  # 卸载包
  npm uninstall 包的名称 -global(-g)|-save(-S)|-dev(-D)


cnpm

  # 安装cnpm
  npm install -g cnpm --registry=https://registry.npm.taobao.org
  # 查看cnpm版本
  cnpm -v

yarn

  # 安装yarn
  npm i yarn -g 

  # 查看yan版本
  yarn --version 

  # 安装包
  yarn add 包的名称 -global(-g)|-save(-S)|-dev(-D)

  # 卸载包
  yarn remove 包的名称 -global(-g)|-save(-S)|-dev(-D)

  # 根据package.json 安装依赖包
  yarn 

node-sass 设置淘宝镜像


npm config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g

yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g