说明
起因
使用 npm
、yarn
过程中安装二进制包老掉链子,比如:node-sass
很久没水文,来刷下存在感
帮助各位解决下安装依赖时掉链子的问题(主要刚入坑人群,俺就是)
介绍
关于npm
、yarn
介绍就不多说了,我们直接奔主题,毕竟直男一枚
首先了解下 .npmrc
和 .yarnrc
.npmrc
文件的作用,就是配置 npm
源;同理 .yarnrc
文件的作用,就是配置 yarn
源。
权重:
命令行 > 项目 .npmrc
> 全局 .npmrc
> 默认镜像源
解决问题
二进制包下载失败:如 node-sass
、phantomjs
使用 cnpm
引发的各种坑
修改默认镜像源为淘宝镜像后安装 node-sass
、phantomjs
依旧报错
我的配置文件
.npmrc 配置
registry=https://registry.npm.taobao.org
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=http://cnpmjs.org/downloads
electron_mirror=https://npm.taobao.org/mirrors/electron/
sqlite3_binary_host_mirror=https://foxgis.oss-cn-shanghai.aliyuncs.com/
profiler_binary_host_mirror=https://npm.taobao.org/mirrors/node-inspector/
chromedriver_cdnurl=https://cdn.npm.taobao.org/dist/chromedriver
复制代码
.yarnrc配置
registry "https://registry.npm.taobao.org"
sass_binary_site "https://npm.taobao.org/mirrors/node-sass/"
phantomjs_cdnurl "http://cnpmjs.org/downloads"
electron_mirror "https://npm.taobao.org/mirrors/electron/"
sqlite3_binary_host_mirror "https://foxgis.oss-cn-shanghai.aliyuncs.com/"
profiler_binary_host_mirror "https://npm.taobao.org/mirrors/node-inspector/"
chromedriver_cdnurl "https://cdn.npm.taobao.org/dist/chromedriver"
复制代码
使用
- 在项目根目录中新建
.npmrc
或者.yarnrc
- 复制对应的配置
- 保存运行
npm i
或者yarn
我的配置中只有一些常用的,如有其他需求可根据对应格式进行添加
推荐大家使用 yarn
再配合淘宝镜像源,简直吃嘛嘛香
其他
篇幅不多有点水,但是解决问题还是很实用的,所以各位小哥哥、小姐姐不要介意
如有更好的方案,欢迎评论区交流
再给自己打广告 Vue全家桶打造自适应 web 音乐播放器