NPM 相关

# NPM 相关

# npm 操作

# 常用命令

npm init 初始化项目 生成 packge.json 文件
npm install 根据packge.json安装依赖

npm cache clean -f  清空npm缓存

npm config set registry https://registry.npmmirror.com 配置nodejs镜像源为淘宝镜像
npm config set registry https://registry.npmjs.org 配置nodejs镜像源为npm官方源
npm config get registry 查看当前镜像源
npm install -g cnpm --registry=https://registry.npmmirror.com 安装cnpm

npm login 命令行登录npm
npm publish 在工程文件目录下执行 发布当前目录为npm包

# 更新项目版本号

# 更新版本号
npm version major
npm version minor
npm version patch

# 预发行版本
npm version premajor
npm version preminor
npm version prepatch

# 设置 npm version 提交时的 git 信息
npm version patch -m "Upgrade to %s for reasons"

查看更多 npm version 指令 (opens new window)

# .npmrc 文件配置

.npmrc 文件是配置项目 npm 包下载下载相关 可以配置成淘宝源

registry=https://registry.npmmirror.com
sass_binary_site=https://registry.npmmirror.com/mirrors/node-sass/
phantomjs_cdnurl=http://cnpmjs.org/downloads
electron_mirror=https://registry.npmmirror.com/mirrors/electron/
sqlite3_binary_host_mirror=https://foxgis.oss-cn-shanghai.aliyuncs.com/
profiler_binary_host_mirror=https://registry.npmmirror.com/mirrors/node-inspector/
chromedriver_cdnurl=https://registry.npmmirror.com/dist/chromedriver

# ncp 检查项目依赖

# 安装

npm install -g npm-check-updates

# 用法

# 检查当前目录下可更新的依赖项
ncu

# 升级 package.json
ncu -u

# 根据更新的 package.json 安装新版本
npm install

# 添加 -u 以获取升级的单行命令
ncu -g

# 使用 --filter 更新指定依赖
# 以下四中写法作用相同
ncu --filter one, two, three
nuc -f one, two, three
ncu one, two, three
ncu one two three

# 使用 --reject 排除指定依赖
ncu --reject one, two, three
ncu -x one, two, three

npm-check-updates -u 仅修改 package.json 文件。运行 npm install 以更新已安装的软件包和 package-lock.json