npm
- 临时使用
1 | npm --registry https://registry.npm.taobao.org install express |
- 持久使用
1 | npm config set registry https://registry.npm.taobao.org |
- 通过cnpm
1 | npm install -g cnpm --registry=https://registry.npm.taobao.org |
- 使用官方镜像
1 | npm config set registry https://registry.npmjs.org/ |
- 查看npm源地址
1 | npm config get registry |
yarn
查看yarn源
1
yarn config get registry
修改源
1 | yarn config set registry 'https://registry.npm.taobao.org' |
npm和yarn 命令对比
npm 命令 | Yarn 命令 | 备注 |
---|---|---|
npm install | yarn install | 安装所有依赖包(依据package.json中的依赖配置参数) |
(N/A) | yarn install –flat | 单版本模式 |
(N/A) | yarn install –har | 生成har文件,记录安装时网络请求性能 |
(N/A) | yarn install –no-lockfile | 不读写lockfile方式 |
(N/A) | yarn install –pure-lockfile | 不生成yarn.lock文件 |
npm install [package] | (N/A) | 安装依赖 |
npm install –save [package] | yarn add [package] | 添加生产模式依赖到项目 |
npm install –save-dev [package] | yarn add [package] [–dev/-D] | 添加开发模式的依赖 |
(N/A) | yarn add [package] [–peer/-P] | 对等模式添加依赖,发布/分享项目时的依赖 |
npm install –save-optional [package] | yarn add [package] [–optional/-O] | 添加可选依赖包 |
npm install –save-exact [package] | yarn add [package] [–exact/-E] | 精准添加某版本的包 |
(N/A) | yarn add [package] [–tilde/-T] | 添加同一次版本的包,如指定版本为1.2.3,可接受1.2.x的其他版本,但不接受1.3.x的版本 |
npm install –global [package] | yarn global add [package] | 添加全局包 |
npm rebuild | yarn install –force | 重建 |
npm uninstall [package] | (N/A) | 删除本地依赖包 |
npm uninstall –save [package] | yarn remove [package] | 删除正式依赖包 |
npm uninstall –save-dev [package] | yarn remove [package] | 删除开发依赖包 |
npm uninstall –save-optional [package] | yarn remove [package] | 删除可选依赖包 |
npm cache clean | yarn cache clean | 清除缓存 |
rm -rf node_modules && npm install | yarn upgrade | 更新包管理器自身 |