node install 代理

临时代理:

npm install --registry=https://registry.npm.taobao.org

自定义代理:

npm config set proxy http://192.168.1.1:10811

npm config set https-proxy http://192.168.1.1:10811

转一篇文章:

https://blog.51cto.com/u_15490526/5516526

Usage

全局安装

// 安装node自带npm,检查是否安装成功,执行如下命令

npm -v // 6.14.15

// yarn

npm install -g yarn

// cnpm

npm install -g cnpm

// pnpm

npm install -g pnpm

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

初始化一个项目

npm init

// OR

yarn init

// 快速生成的package.json默认配置

npm/yarn init -y

1.

2.

3.

4.

5.

6.

安装项目依赖

// npm / cnpm / pnpm

// 简写,全称 npm install

npm i [package]

// yarn

yarn add [package]

// 安装指定版本

npm i [package]@[version]

yarn add [package]@[version]

// 小栗子

// 安装 jquery

npm i jquery@3.0.0

// 查看package.json

"jquery": "^3.0.0"

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

16.

17.

Tips1 意外情况

我们经常会在安装一半退出在继续安装会报错,这是因为有缓存的原因。

npm cache clean --force

1.

Tips2 --save--dev意思

npm install vue

npm install vue --save

npm install @babel/core --save-dev

查看package.json,文件内容不发生改变,在运行项目且有引用该依赖时能正常运行,当npm i时候,不会安装该依赖。

--save

查看package.json 会有一个dependencies对象,里面就是项目运行需要的依赖。

dependencies 代表项目运行所依赖的模块

简写 -S

npm install express -S

--save-dev

查看package.json 会有一个devDependencies对象,里面就是项目开发时候需要的依赖。

devDependencies 代表项目开发所需要的模块

如:babel 是发布时,将 ES6 代码编译成 ES5 ,那么 babel 就是devDependencies。

简写 -D

npm install express -D

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

16.

17.

18.

19.

Tips3 ^和~的区别

// package.json中^和~的区别

"vue": "~2.6.0",

"es6-promise": "^2.0.0"

~符号

假设vue版本已经更新到2.7.0以上,当我们重新安装项目依赖,只会匹配到2.6.x的最新版本,不会匹配到2.7.0及以上

^符号

假设es6-promise更新3.0.0,当我们重新安装项目依赖,es6-promise始终是2.0.0

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

Tips4 版本号代表含义

"vue": "2.6.0"

第一位表示:主版本号,常用于大版本更新,可能不兼容旧版本。

如Vue2.0和Vue3.0,虽然说向下兼容,但是部分语法存在兼容问题。

第二位表示:次版本号,增加了新的功能,基本向下兼容。

第三位表示:补丁号, 修复了bug等。

1.

2.

3.

4.

5.

6.

7.

8.

全局包管理

// 查看当前哪些包需要更新

npm outdated -g --depth=0

@vue/cli 4.5.9 4.5.13 4.5.13 global

npm 6.14.15 6.14.15 7.24.0 global

pnpm 5.17.3 5.18.10 6.15.1 global

// 更新全局的依赖包

npm update -g

// 更新依赖包

npm update pnpm

// 可能报错 Remove the existing file and try again, or run npm with --force to overwrite files recklessly.

1. 卸载 pnpm

npm uninstall -g pnpm

清理 npm 缓存

npm cache clean --force

重新安装

npm i pnpm -g

// 第二种 强制安装依赖

npm install -g pnpm --force

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

16.

17.

18.

19.

20.

21.

22.

23.

24.

25.

26.

升级依赖包

"vue": "^2.6.0"

npm update vue

yarn upgrade vue@2.6.14 指定版本

yarn upgrade vue@^ //选择指定版本

// "vue": "^2.6.14"

1.

2.

3.

4.

5.

6.

7.

8.

删除依赖包

"vue": "^2.6.0"

npm uninstall vue

yarn remove vue

1.

2.

3.

4.

5.

更新项目中所有依赖项

npm-check

npm-check-updates

二者目的相同,只是在更新过程中的一些交互展示形式存在一定的差异

npm-check-updates

安装

npm install -g npm-check-updates

1.

使用

// 查看可更新包

ncu

[====================] 12/12 100%

@vssue/api-github-v4 ^1.4.0 → ^1.4.7

@vssue/vuepress-plugin-vssue ^1.4.6 → ^1.4.8

@vuepress-reco/vuepress-plugin-back-to-top ^1.5.7 → ^1.6.0

@vuepress/plugin-google-analytics ^1.8.1 → ^1.8.2

@vuepress/plugin-pwa ^1.8.1 → ^1.8.2

dayjs ^1.10.4 → ^1.10.7

vuepress ^1.8.1 → ^1.8.2

vuepress-plugin-live2d-model ^1.0.0 → ^1.0.7

vuepress-plugin-one-click-copy ^1.0.2 → ^1.0.6

// 升级所有依赖项

ncu -u

ncu -u vuepress dayjs ...

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

16.

17.

npm-check

安装

npm install npm-check -g

1.

使用

// 查看可更新包

npm-check

// 升级所有依赖项

npm-check -u

1.

2.

3.

4.

5.

切换国内镜像

目前常用的镜像列表

npm ---- https://registry.npmjs.org/

cnpm --- https://registry.nlark.com/

taobao - https://registry.npm.taobao.org

yarn --- https://registry.yarnpkg.com/

tencent- https://mirrors.cloud.tencent.com/npm/

1.

2.

3.

4.

5.

查看yarn当前镜像源

yarn config get registry

npm config get registry

cnpm config get registry

pnpm config get registry

//https://registry.nlark.com/

1.

2.

3.

4.

5.

6.

7.

8.

9.

设置镜像源

// 全局使用

yarn config set registry https://registry.npm.taobao.org

cnpm config set registry https://registry.nlark.com/

// ...

// 临时在项目中使用

npm install --registry https://registry.npm.taobao.org

1.

2.

3.

4.

5.

6.

7.

8.

还原镜像源

npm config set registry https://registry.npmjs.org

// 根据上面的镜像列表替换就行。

1.

2.

nrm / yrm 管理镜像源工具

​​yrm/nrm​​​ 不仅可以快速切换镜像源,还可以测试自己网络访问不同源的速度,且​​yrm/nrm​​用法都相同。

安装 yrm /nrm

npm install -g yrm

// or

npm install -g nrm

1.

2.

3.

列出当前镜像源列表

yrm ls

npm ----- https://registry.npmjs.org/

cnpm ---- http://r.cnpmjs.org/

taobao -- https://registry.npm.taobao.org/

nj ------ https://registry.nodejitsu.com/

rednpm -- http://registry.mirror.cqupt.edu.cn

skimdb -- https://skimdb.npmjs.com/registry

yarn ---- https://registry.yarnpkg.com

1.

2.

3.

4.

5.

6.

7.

8.

9.

使用,测试

yrm use taobao

// https://registry.npm.taobao.org/

yrm test taobao

// taobao - 187ms

1.

2.

3.

4.

5.

建议

Windows用户

推荐使用​​yarn/npm​​​,可能​​cnpm/pnpm​​​安装速度优于​​yarn/npm​​​,但是可能造成诡异的 bug,比如项目运行不起来等等,最简单直接的方法就是删除​​node_modules​​重新安装。

如图所示,图中的项目通过​​pnpm/cnpm​​​安装的依赖项, 直接运行不起来,之所以只针对​​​Win​​​系统,因为​​Win​​​系统删除​​node_modules​​​快则几分钟,慢则十几分钟,而​​mac​​直接秒删,试错成本低可以尝试。

-----------------------------------

npm、yarn、cnpm、pnpm 使用操作都在这了

https://blog.51cto.com/u_15490526/5516526

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

chinabinlang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值