npm添加淘宝镜像

2019-06-27  本文已影响0人  是河兔兔啊

cli常用命令

yarn add 添加依赖包

yarn add webpack  安装 latest   最新版本
yarn add package-name@1.2.3    从 registry 里安装这个包的指定版本。
yarn add package-name@tag      安装某个 “tag” 标识的版本(比如 beta、next 或者 latest)

yarn cache 全局缓冲

yarn cache list 列出已缓存的每个包

yarn cache dir  当前的 yarn 全局缓存在哪里

yarn cache clean  运行此命令将清除全局缓存

yarn config set cache-folder <path> 配置缓存目录。

yarn config 配置文件

yarn config 查看配置

C:\Users\用户>yarn config get bin-links   查看某一项配置
true

yarn config set registry 'https://registry.npm.taobao.org'  转成淘宝镜像

yarn global 全局安装

// yarn 默认是不建议全局安装的,因为全局安装的包无法通过.lock来捕获到,当你的项目移到别的地方运行的时候就可能出现问题

yarn global add webpack

yarn global upgrade webpack

yarn global remove webpack

yarn info 查看包的信息

yarn info react 

yarn info react --json json化一下

yarn info react@15.3.0  查看指定版本

yarn install 安装全部依赖

yarn install
或者
yarn

yarn remove 移除依赖

yarn remove webpack

yarn run 运行一个定义好的脚本

{
  "name": "my-package",
  "scripts": {
    "build": "babel src -d lib",
    "test": "jest"
  }
}

yarn upgrade 更新

yarn upgrade
yarn upgrade left-pad
yarn upgrade left-pad@^1.0.0

yarn why 显示一个包为何要安装

yarn why jest

yarn publish 发布自己的包

yarn init 初始化一个项目

npm config set registry https://registry.npm.taobao.org
npm config set disturl https://npm.taobao.org/dist
npm config set electron_mirror https://npm.taobao.org/mirrors/electron/
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs/
yarn config set registry https://registry.npm.taobao.org -g
yarn config set disturl https://npm.taobao.org/dist -g
yarn config set electron_mirror https://npm.taobao.org/mirrors/electron/ -g
yarn config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/ -g
yarn config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs/ -g
yarn config set chromedriver_cdnurl https://cdn.npm.taobao.org/dist/chromedriver -g
yarn config set operadriver_cdnurl https://cdn.npm.taobao.org/dist/operadriver -g
yarn config set fse_binary_host_mirror https://npm.taobao.org/mirrors/fsevents -g

如果需要更改镜像可以全局安装nrm nvm yrm mirror-config-china等包
npm查找全局安装包: npm root -g
查看安装的所有全局包: npm ls -g
仅查看一级目录:npm ls -g --depth 0 | grep packageName --depth 0
yarn查找全局安装包: yarn global dir
配置文件位置 :c:\Users\用户名\ 名称: .npmrc .yarnrc
问题描述: npm 和 yarn 的一些缓存和全局安装的包,默认都会在C盘存储,这个对于C盘的宝贵空间来说,实在是不能忍啊。
于是乎,百度了如何改变npm默认的缓存位置
在CMD命令行中执行

1.改变npm 全局安装位置

npm config set prefix "你的磁盘路径"

这里是我的路径

npm config set prefix "D:\appCache\nodejs\node_global"

2. 改变 npm 缓存位置

npm config set cache "你的磁盘路径"

这里是我的路径

npm config set cache "D:\appCache\nodejs\node_cache"

然后配置一下系统环境变量
D:\appCache\nodejs\node_globalD:\appCache\nodejs\node_global\node_modules这两个添加到你的系统环境变量中。
Yarn 的安装: 在官网下载 安装包。
修改全局安装位置 和 缓存位置
在CMD命令行中执行

1.改变 yarn 全局安装位置

yarn config set global-folder "你的磁盘路径"

2.然后你会在你的用户目录找到 .yarnrc 的文件,打开它,找到 global-folder ,改为 --global-folder

这里是我的路径

yarn config set global-folder "D:\appCache\yarn\global"

2. 改变 yarn 缓存位置

yarn config cache-folder "你的磁盘路径"

这里是我的路径

yarn config cache-folder "D:\appCache\yarn\cache"

在我们使用 全局安装 包的时候,会在 “D:\appCache\yarn\global”下 生成 node_modules.bin 目录
我们需要将D:\appCache\yarn\global\node_modules\.bin整个目录 添加到系统环境变量中去,否则通过yarn 添加的全局包 在cmd 中是找不到的。
检查当前yarn 的 bin的 位置
yarn global bin

检查当前 yarn 的 全局安装位置
yarn global dir

nvm设置镜像

nvm 设置淘宝镜像
windows版本
设置npm_mirror:
nvm npm_mirror https://npm.taobao.org/mirrors/npm/

设置node_mirror:
nvm node_mirror https://npm.taobao.org/mirrors/node/
linux版本
在.bashrc中添加下面的内容
export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node

写在最后
为什么说折腾呢
因为我之前只 是改了 npm 和yarn的 全局安装位置和缓存位置,没有添加系统环境变量
然后在全局安装 vue-cli3 的时候,就蛋疼了,开始是报 powershell 脚本不能执行的问题。然后又是报 目录错误的问题,然后又是找不到命令。
当我把这些坑踩完

上一篇下一篇

猜你喜欢

热点阅读