关于javascript:前端开发必备-NPM

29次阅读

共计 687 个字符,预计需要花费 2 分钟才能阅读完成。

介绍

  1. NPM 是基于 node.js 开发的软件
  2. NPM 是 node.js 默认包管理工具,古代前端开发必备

检测 NPM 是否装置胜利

npm -v

NPM 镜像

因为 NPM 默认镜像 是在国外,所以下载速度很慢很不稳固,所以须要切换回国内的镜像(国内最闻名的镜像是阿里的)

  • 查看 NPM 以后镜像
npm config get registry
  • 设置镜像
npm config set registry https://registry.npm.taobao.org
  • [举荐] nrm 镜像管理工具
// 装置
npm i nrm -g --registry=https://registry.npm.taobao.org

// 查看所有镜像以及以后应用的镜像
nrm ls

// 切换镜像
nrm use taobao

如何更新 NPM

// npm 说到底也是一个一般的包
npm i npm -g

根本应用

  • 装置
// 生产环境
npm i xxx
npm i xxx -S
npm i xxx@2.0.1 -S

// 开发环境
npm i xxx -D

留神:
1、可用于更新
2、不指定版本的话,就会只依据 package.json 文件的版本规定更新 
  • 卸载
// 卸载全局
npm uninstall xxx -g

// 卸载开发
npm uninstall xxx -D

// 卸载生产
npm uninstall xxx -S
  • 更新
// 更新全局所有包
npm update -g 

// 更新全局某包
npm update -g xxx

// 更新本地所有包
npm update 

// 更新本地某包
npm update xxx

留神:1、会依据 package.json 文件的版本规定更新 
  • 查看
// 查看全局某包
npm ls -g xxx

// 查看本地某包
npm ls xxx

// 查看以后我的项目所依赖的包
npm ls

正文完
 0