> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# 包管理工具换源

**Yarn** 和 **NPM(npx)** 是主流的资源包管理工具，默认安装使用时，下载资源的速度非常慢。其主要原因是 **npm** 资源包默认的服务器在国外，当使用 **yarn** 和 **npm** 安装资源包时候，速度非常慢。为了解决下载速度的问题，大多使用阿里的 **淘宝镜像**（**cnpm**）来解决下载速度慢安装失等问题。

## 安装淘宝镜像

- 安装 [**淘宝 NPM 镜像**](https://developer.aliyun.com/mirror/NPM?from=tnpm) 前默认已安装 [**Node.js**](https://nodejs.org/zh-cn/)

```bash title="淘宝镜像地址"
npm install -g cnpm --registry=https://registry.npmmirror.com
```

- 安装模块

```bash title="安装模块"
cnpm install [name]
```

- 移除模块

```bash title="移除模块"
cnpm uninstall [name]
```

## 查看源/切换源

- 查看源

```bash title="查看源地址"
yarn config get registry
// yarn 当前(默认)镜像源：https://registry.yarnpkg.com/

npm config get registry
// npm 当前(默认)镜像源：https://registry.npmjs.org/
```

- 设置源

```bash title="设置源地址"
yarn config set registry https://registry.npmmirror.com
// yarn、npm 切换淘宝镜像源
npm config set registry https://registry.npmmirror.com
```

- **Yarn 下载**

- [**Yarn 包管理地址**](https://classic.yarnpkg.com/zh-Hans/)

:::tip 提示
「点击 🫱 查看 👀」[Yarn 中文文档](https://yarn.bootcss.com/docs/install/#windows-stable)
::::

## 查看 npm 安装的插件

```bash title="查看全局安装的包"
// npm 查看全局安装的包
npm list -g --depth -0

// yarn 查看全局安装的包
yarn global list
```

## 清除缓存

```bash title="清除缓存"
// npm 清除缓存
npm cache clean -f

// yarn 清除缓存
yarn cache clean
```

## 镜像配置参考

- [npmmirror 镜像站](https://npmmirror.com) 「🔥 👀」

:::danger 温馨提示
淘宝镜像旧源地址`http://npm.taobao.org` 和 `http://registry.npm.taobao.org` 于 **_2022.06.30_** 号正式下线和停止 DNS 解析。现在启用的镜像地址为：`https://registry.npmmirror.com`
:::
