Node安装
# Node 安装
# pnpm 安装
npm 全局安装
npm install pnpm -g
1
设置淘宝源
pnpm config get registry # 查看源
pnpm config set registry http://registry.npm.taobao.org # 切换淘宝源
1
2
2
基本命令
# 安装依赖package.json
pnpm install 包
# install 简写
pnpm i 包
# -S 默认写入dependencies
pnpm add 包
# -D devDependencies dev开发环境
pnpm add -D
# -g 全局安装
pnpm add -g
# 移除包
pnpm remove 包
# 移除全局包
pnpm remove 包 --global
# 更新所有依赖项
pnpm up
# 更新包
pnpm upgrade 包
# 更新全局包
pnpm upgrade 包 --global
# 设置存储路径
pnpm config set store-dir /path/to/.pnpm-store
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
27
28
29
30
31
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
27
28
29
30
31
# yarn 安装
npm 全局安装
npm install -g yarn
yarn --version
1
2
3
2
3
设置淘宝镜像
yarn config set registry https://registry.npm.taobao.org -g
yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g
1
2
2
基本命令
# 初始化项目 同npm init,执行输入信息后,会生成package.json文件
yarn init
# yarn的配置项
# 显示所有配置项
yarn config list
# 显示某配置项
yarn config get <key>
# 删除某配置项
yarn config delete <key>
# 设置配置项
yarn config set <key> <value> [-g|--global]
# 安装包
# 安装package.json里所有包,并将包及它的所有依赖项保存进yarn.lock
yarn install
# 安装一个包的单一版本
yarn install --flat
# 强制重新下载所有包
yarn install --force
# 只安装dependencies里的包
yarn install --production
# 不读取或生成yarn.lock
yarn install --no-lockfile
# 不生成yarn.lock
yarn install --pure-lockfile
# 添加包(会更新package.json和yarn.lock):
# 在当前的项目中添加一个依赖包,会自动更新到package.json和yarn.lock文件中
yarn add [package]
# 安装指定版本,这里指的是主要版本,如果需要精确到小版本,使用-E参数
yarn add [package]@[version]
# 安装某个tag(比如beta,next或者latest
yarn add [package]@[tag]
# 不指定依赖类型默认安装到dependencies里,你也可以指定依赖类型:
# 加到 devDependencies
yarn add --dev/-D
# 加到 peerDependencies
yarn add --peer/-P
# 加到 optionalDependencies
yarn add --optional/-O
# 默认安装包的主要版本里的最新版本,下面两个命令可以指定版本:
# 安装包的精确版本。例如yarn add [email protected]会接受1.9.1版,但是yarn add [email protected] --exact只会接受1.2.3版
yarn add --exact/-E
# 安装包的次要版本里的最新版。例如yarn add [email protected] --tilde会接受1.2.9,但不接受1.3.0
yarn add --tilde/-T
# 发布包
yarn publish
# 移除一个包 会自动更新package.json和yarn.lock
yarn remove <packageName>
# 更新依赖 用于更新包到基于规范范围的最新版本
yarn upgrade
# 运行脚本 用来执行在 package.json 中 scripts 属性下定义的脚本
yarn run
# 显示某个包的信息 可以用来查看某个模块的最新版本信息
yarn info <packageName>
# 缓存
yarn cache
# 列出已缓存的每个包
yarn cache list
# 返回 全局缓存位置
yarn cache dir
# 清除缓存
yarn cache clean
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Ubuntu 中如何更新 node
# 首先必须安装node 和 npm
apt-get install -y nodejs
apt-get install -y npm
# 查看版本 v10.24.0 使用apt-get安装的版本太低了我们需要更新
node --version
# 安装 n
npm install n -g
# 使用 n更新node lst版本
n lts
# npm 更新
npm install npm -g
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
编辑 (opens new window)
上次更新: 2025/01/01, 10:09:39