npm使用手册

目录

# 包的管理
# ----》创建包
# ----》安装包
# ----》删除包
# ----》发布包
# ----》更新包
# ----》列出包
# 缓存目录
# 淘宝镜像
# 遇到问题
# 其他杂项

正文

#创建包

npm init
//npm init --yes

#安装包

//全局安装
npm install -g 模块名称

//本地安装
npm install 模块名称

//生产依赖
npm install 模块 --save
npm install 模块 --S

//开发依赖
npm install 模块 --save-dev
npm install 模块 -D

#删除包

//全局删除
npm uninstall -g package
//局部删除
npm uninstall 模块
npm uninstall 模块 --save
npm uninstall 模块 --save-dev

#发布包

//登陆
npm login

//添加账户
//第一次发布npm adduser

//发布
npm publish

//撤销
npm unpublish 包名

#更新包

//1.修改包的版本(package.json里的version字段)
//2.npm publish

一套版本控制标准

类目 描述
补丁 修复bug,小改动,增加z
小改 增加了新特性,但能向后兼容,增加y
大改 有很大的改动,无法向后兼容,增加x

一批改变版本指令

类目 描述
大改 npm version major
小改 npm version minor
补丁 npm version patch

#列出包

//最上层包
npm ls --depth=0

//简要说明
npm la

缓存目录

//查看
npm config get cache

//清空
rm -rf ~/.npm/*
//or npm cache clean
//or

//安装
npm install --cache-min 9999999 

淘宝镜像

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

//还原镜像 npm config set registry http://registry.npmjs.org 

遇到问题

问题:npm 安装出现 UNMET DEPENDENCY 的解决方案
解决:
https://lellansin.wordpress.com/2014/02/27/npm-安装出现-unmet-dependency-的解决方案/

问题:code EINTEGRITY
解决:
https://stackoverflow.com/questions/48852553/unable-to-create-new-angular-project-err-code-eintegrity

问题:
Unexpected end of JSON input while parsing near '...":"^0.1.0","yargs":"^'
解决:npm cache clean --force && npm install --registry=https://registry.npm.taobao.org
https://blog.csdn.net/csdn_yudong/article/details/79781842

问题:
莫名其妙的问题
解决:
npm install npm -g
npm cache clear && rm -rf node_modules && npm install

问题:
npm ERR! peer dep missing: ajv@^6.0.0, required by [email protected]
解决:
npm ll [email protected]
npm install ajv@^6.0.0

问题:
在安装完成我们的npm模块后,根据当时的各软件模版版本情况下载合适的版本到本地,今天安装调试ok,明天很有可能就有新的依赖的版本发布,而这时如果再次执行npm install就有可能下载了不同版本的依赖,很有可能会产生问题!怎么办?
解决:
方案1
npm install
npm shrinkwrap

其他杂项

查看版本
npm -v

查看帮助
npm -h
npm help config

配置管理
//设置配置
npm config set   [-g|--global]
npm set   [-g|--global]

//查看配置

查看默认配置:npm config list [-l] [--json]
npm config list -l
npm config ls -l 
npm c ls -l 
npm config list --json
查看当前配置:
npm config list

查看某一键值:npm config get 
npm config get tmp
npm c get tmp
查看某一键值:npm get 
npm get tmp

//删除配置
npm config delete 

//编辑配置
npm config edit
//编辑全局配置文件:npm config edit --global
//编辑局部配置文件:npm config edit


软链管理
//创软链接
cd /f/webMyLib/cssLib-dev-tool
npm link

//查看软链
npm config get prefix

//连软链接
cd f/webMyLib/css-wave
npm link cssLib-dev-tool
备注:package-name 是package.json中的名字, 不是目录名字.

//现在开发

//断软链接
cd f/webMyLib/css-wave
 npm unlink cssLib-dev-tool

//删除软链
cd /f/webMyLib/cssLib-dev-tool
npm unlink

//删除有问题的包
npm ls
//or npm ls package with error
npm uninstall 

//查看当前配置
npm config ls

//清除没有使用的包
npm prune

//查看某个包的依赖
npm ll gulp-less

--------------------------------设置npm安装程序时的默认目录
// 设置npm全局安装程序时的目录前缀

npm config set prefix "D:\Program Files\nodejs\X64\node_global"


// 设置npm安装程序时的缓存位置
npm config set cache "D:\Program Files\nodejs\X64\node_cache"


// 设置环境变量NODE_PATH 
NODE_PATH =D:\Program Files\nodejs\X64\node_global\node_modules
//or?
//NODE_PATH =D:\Program Files\nodejs\X64\node_global

你可能感兴趣的:(npm使用手册)