npm命令,开发依赖,版本号【正解】

npm i 私有库的包例如gitlab:
git+ssh://git@github.com:npm/cli.git#v1.0.27
"axios": "latest", // 最新版本
 // semver:^1.6会安装上 1.6.68
"@rrcfe/sdk": "git+http://gitlab.rrc.com/fe/node-sdk.git#semver:^1.6",
git+https://isaacs@github.com/npm/cli.git
git://github.com/npm/cli.git#v1.0.27
git+http://gitlab.rrc.com/fe/notify-sdk.git#master // 分支
ssh:git@gitlab.rrc.com:fe-template/jenkins-scripts.git // yarn支持ssh

复制代码
版本号~和^的区别:
  • ~会匹配最近的小版本依赖包,比如~1.2.3会匹配所有1.2.x版本,但是不包括1.3.0
  • ^会匹配最新的大版本依赖包,比如^1.2.3会匹配所有1.x.x的包,包括1.3.0,但是不包括2.0.0
  • 在项目根目录的package.json里面和 node_modules里面的 package.json 有区别
  1. 项目根目录的package.json 里面 ^1.2.3 会安装到最高的1.2.x版本,想改更高,手动改
  2. node_modules的 package.json 里面 ^1.2.3 会安装到最高的1.x.x版本
dependencies 和 devDependencies(开发依赖)的区别:
  • dependencies依赖包在项目根目录或者node_modules里面的 package.json 里面 npm i的时候 都会安装
  • devDependencies 在node_modules里面的 package.json 里面 npm i的时候 不会安装
npm version

semver 约定一个包的版本号必须包含3个数字,格式必须为 MAJOR.MINOR.PATCH, 意为 主版本号.小版本号(增加新功能).修订版本号(fix bug). 可以简单地将版本号中相应的数字加1.

npm version major|minor|patch
复制代码
查看npm安装目录:
npm root -g
复制代码
查看npm的prefix和cache路径配置信息:
npm config get prefix
npm config get cache
复制代码
修改全局和缓存路径
  • 先在设置路径目录下新建两个文件夹(eg:node_global和node_cache),eg:直接在nodejsd安装目录下
npm config get prefix
npm config get cache
复制代码
  • 设置路径 通常不用改
npm config set prefix "D:\ProgramFile\nodejs\node_modules\node_global"
 
npm config set cache "D:\ProgramFile\nodejs\node_modules\node_cache"

复制代码
设置npm镜像源
npm config set registry https://registry.npm.taobao.org --global
// 设置node源码的源
npm config set disturl https://npm.taobao.org/dist --global
复制代码
查看镜像的配置结果
npm config get registry
复制代码
确保 当前源 在npm 上
npm config set registry https://registry.npmjs.org/
复制代码
快捷修改.npmrc配置文件
npm config edit

// 查看
npm config list
复制代码
npm 用户名
npm whoami
复制代码
打开包的官网
npm docs express
npm home vue
复制代码
cnpm同步模块
// 直接通过 sync 命令马上同步一个模块, 只有 cnpm 命令行才有此功能:
cnpm sync connect
// 当然, 你可以直接通过 web 方式来同步: /sync/connect
open https://npm.taobao.org/sync/connect
复制代码
.npmrc 文件配置只针对当前项目
package-lock = false // 如果用yarn 加上
registry=https://registry.npm.taobao.org/
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs
electron_mirror=https://npm.taobao.org/mirrors/electron/
复制代码
.npmignore 包发布时候忽略文件,没有这个文件会读取.gitignore
  • 想设置发布文件的白名单,设置package.json中的files属性。
files:["package.json","src"]
复制代码
  • 这里的优先级是files>.npmignore>.gitignore
.DS_Store
.idea
node_modules
.git
reports
npm-debug.log*
stats.json
coverage
.vscode/
.tmp
.idea
build
复制代码
other
  • 使用npm install下载你想要起的包名字,如果报错404,那么你的包名是可用的。
  • 使用 npm install -g 将你当前的项目安装到全局环境,现在你可以在命令行使用"my-cli"命令了。
  • npm adduser
  • npm publish
  • 卸载npm uninstall <pkg> 或者 npm uninstall <name>@[<version>]
  • 更新某一个pkg版本npm update <pkg>@<version>
文件通配符:glob模式
  • * 匹配任意多个字符,除了/
  • ? 匹配除了/之外的单个字符
  • ** 匹配任意多个字符,包括 /
  • {}匹配用逗号分割的 or 列表
  • ! 用在模式的开头,表示取反.npmignore
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值