配置文件
项目配置
.npmrc
sharp_binary_host=https://npmmirror.com/mirrors/sharp
sharp_libvips_binary_host=https://npmmirror.com/mirrors/sharp-libvips
registry=https://registry.npmmirror.com/
全局配置
.npmrc
配置文件
# 使用cmd 创建.npmrc文件
type>nul .npmrc
# 指定源
registry=https://registry.npmmirror.com/
sass_binary_site=https://registry.npmmirror.com/mirrors/node-sass/
electron_mirror=https://registry.npmmirror.com/mirrors/electron/
ELECTRON_CUSTOM_DIR=9.0.0 # 指定electron的版本
npm_config_target="1.7.10" # electron version
npm_config_runtime="electron" # 为elelctron编译
npm_config_disturl="https://atom.io/download/electron" # 资源下载地址
npm_config_build_from_source="true" # 从源码编译
strict-ssl=false # 取消ssl验证
- 一键导入
# powershell
echo `
"registry=https://registry.registry.npmmirror.com`
sass_binary_site=https://registry.npmmirror.com/mirrors/node-sass/`
electron_mirror=https://registry.npmmirror.com/mirrors/electron/`
"> $env:USERPROFILE\.npmrc
配置备份
ELECTRON_MIRROR=http://registry.npmmirror.com/mirrors/electron/
registry=https://registry.registry.npmmirror.com/
electron_mirror=http://registry.npmmirror.com/mirrors/electron/
PYTHON_MIRROR=http://registry.npmmirror.com/mirrors/python
msvs_version=2017
sass_binary_site=https://registry.npmmirror.com/mirrors/node-sass/
cache=D:\temp\nodejs\npm
prefix=D:\temp\nodejs\prefix
electron_config_cache=D:\temp\nodejs\Electron
strict-ssl=false
配置缓存
npm默认缓存的目录
# powershell
$Env:LOCALAPPDATA+"\npm-cache"
# 设置缓存目录
npm config set cache "xxxx/xxx"
# 包安装的目录
npm config set prefix "D:\ProgramFiles\nodejs\node_modules\npm\global_node_modules"
# 清空缓存
npm cahce clear
# 强制清除缓存
npm cache clear -f
npm cache clear --force && npm install --no-shrinkwrap --update-binary
第三方源设置
手动切换
# 官方
npm config set registry https://registry.npmjs.org/
# 淘宝源
npm config set registry https://registry.registry.npmmirror.com/
--registry=https://registry.npmjs.org/
官方源--registry=https://registry.registry.npmmirror.com
淘宝源--registry=https://mirrors.huaweicloud.com/repository/npm/
华为源
安装时指定
# 直接使用安装指令,即可更新已安装的包
npm install {packageName} -g --registry=https://registry.registry.npmmirror.com
npm install typescript -g --registry=https://registry.registry.npmmirror.com