fangmd / blogsource

6 stars 0 forks source link

npm 常用命令记录 #3

Open fangmd opened 3 years ago

fangmd commented 3 years ago

检查依赖是否需要升级

npm outdated

查看 npm 全局安装了那些包

npm ls -g --depth 0

npm 全局包安装位置 /usr/local/lib/node_modules

操作全局安装包

npm i -g [xxx]
npm uninstall -g [xxx]

缓存清除

缓存位置: ~/.npm

 npm cache clean --force

升级 npm 版本

npm update -g npm
fangmd commented 3 years ago

在项目目录下:

npm link

取消 link:

// xxx 是项目名称

npm unlink xxx

rm -rf /usr/local/lib/node_modules/xxx

自动定义命令行功能的时候会用到这个。(自定义 cli 时用到了)

fangmd commented 3 years ago

npmrc

项目下 npm 配置文件:.npmrc

官方源:

registry=https://registry.npmjs.org

taobao 源:

registry=https://registry.npmmirror.com

全局 npmrc

MacOS:

/Users/用户名/.npmrc
fangmd commented 3 years ago

查看

npm config get registry

// or

npm config list

临时设置源

npm install --registry=https://custom.npm.registry.com/ 

设置源

npm config set registry https://registry.npmjs.org

pnpm set registry https://registry.npmjs.org/

nrm 管理源

npm i -g nrm

基本使用:

# 查看所有源
npm ls

# 切换源 
nrm use [xxx]

# 添加源
nrm add  <registry> <url> [home]
nrm add 58 http://ires.58corp.com/repository/58npm/
fangmd commented 2 years ago

发布 npm 包

npm publish --access public
npm publish --registry=http://xxxxx/repository/npm-hosted/
fangmd commented 1 year ago

package.json

解决依赖库的 peer 依赖版本比项目中使用的高的问题

  "overrides": {
    "vue": "2.6.10"
  }