-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpm.txt
99 lines (45 loc) · 1.9 KB
/
npm.txt
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
72
73
74
75
76
77
78
79
80
81
82
83
84
(1)常用命令
npm install xxx --save 安装模块(生产环境依赖)
npm install xxx --save-dev 安装模块(开发环境依赖)
npm install xxx -g 将模块安装到全局环境中
npm ls 查看安装的模块及依赖
npm ls -g 查看全局安装的模块及依赖
npm uninstall xxx (-g) 卸载模块
npm cache clean 清理缓存
(2)全局npm包 和 本地npm包
比如:全局@angular/cli的版本为1.2.1 而本地@angular/cli的版本为1.0.1,
在项目中如果package.json中含有该npm包并且node-modules中已经安装,则会使用本地@angular/cli,即版本为1.0.1的@angular/cli,
如果在项目的外部,则会使用版本为1.2.1的@angular/cli,比如ng new 项目名会使用@angular/cli1.2.1
(3)查看全局或本地安装了哪些npm包
全局:npm list -g --depth 0 (如果没有参数--depth 0则全局npm包依赖的npm包也会打印出来,太多没法看)
本地:npm list --depth 0 (如果没有参数--depth 0则本地npm包依赖的npm包也会打印出来,太多没法看)
(4)
$ npm config --help ------查看npm config 下有哪些可以使用的命令
npm config set <key> <value> ------设置某一项配置
npm config get [<key>] ------查看某一项配置
npm config delete <key> ------删除某一项配置
npm config list ------"npm config ls -l" to show all defaults.
npm config edit ------编辑某一项配置
npm set <key> <value> == npm config set <key> <value>
npm get [<key>] == npm config get [<key>]
(5)
在装完node后,要全局npm i node-sass -g,不然有的npm包安装时会报错,再不行就使用 npm rebuild node-sass
(6)清除npm缓存: npm cache clean --force
(7)npm publish
带命名空间的npm包安装
1.在官网注册账号
2.在用户界面添加一个组织(Organizations)名称,比如叫test
3.配置package.json,主要包含:
{
"name": "@test/xxx", // @组织名称/包名
"version": "1.0.0", // 版本号
"main": "dist/index.js", // 包入口
"files": [ // 发布的文件夹以及文件列表
"dist"
],
"publishConfig": {
"access": "public", // 发布到共有仓库
"registry": "https://registry.npmjs.org" // 仓库地址
}
}
4.发布包:npm publish