npm命令行


待补充

1. 查看包版本

以Vue为例。

命令描述
npm view vue versions查看npm服务器上vue的所有版本信息
npm view vue version查看npm服务器上vue的最新版本信息
npm info vue查看vue全部版本信息,包含更多信息
npm ls vue查看本地安装的vue信息
npm ls vue -g查看全局安装的vue信息

2. 安装包

命令描述
npm install vue -g全局安装vue
npm install vue本地安装vue
npm install vue@2.6.12本地安装指定版本的vue
npm install vue --save本地安装vue, 将依赖包名称添加到 package.json 文件 dependencies 下
npm install vue --save-dev本地安装vue, 将依赖包名称添加到 package.json 文件 devDependencies 下
  • --save 可以简写为 -S 是指发布之后还依赖的包;
  • --save-dev 可以简写为 -D 是指开发是需要依赖的包,发布后不再需要;

3. 卸载安装包

命令描述
npm uninstall vue -g删除全局包
npm uninstall vue删除本地包

4. 更新安装包

  1. 更新指定安装包,需要提前修改package.json的安装包版本号。
npm update vue
  1. 全局更新:
  • 查看所有可以更新的安装包
npm outdated
  • 安装npm-check-updates模块
npm i npm-check-updates -g
  • 查看可更新安装包
ncu
  • 更新全部可更新安装包
ncu -u

可以根据实际情况添加作用范围:-D、-S 或 -g

5. 修改项目版本号

  1. 版本号格式:major.minor.patch
  2. 预设版本号格式:premajor.preminor.prepatch-prerelease
命令描述
npm version major修改主版本号 1.0.0 > 2.0.0
npm version minor修改次版本号 1.0.0 > 1.1.0
npm version patch修改补丁号 1.0.0 > 1.0.1
npm version premajor修改预设主版本号 1.0.0 > 2.0.0-0
npm version preminor修改预设次版本号 1.0.0 > 1.1.0-0
npm version prepatch修改预设补丁号 1.0.0 > 1.0.1-0
npm version prerelease修改预设发布号 1.0.0 > 1.0.0-0

6. npm配置

命令描述
npm config list查看基本信息,仓库地址,CMD路径,根目录等
npm config ls同上
npm config ls -l查看npm全部信息
npm config get key查看npm某项配置信息,key:配置名称
npm config set key value设置某配合信息,key: 配置名称; value: 配置值

6.1 切换仓库到淘宝镜像

// 永久切换
npm config set registry https://registry.npm.taobao.org
// 验证切换是否成功
npm config get registry
// 一次性切换
npm i vue --registry https://registry.npm.taobao.org

6.2 添加cnpm指令

npm i cnpm -g --registry https://registry.npm.taobao.org

7. 发包

将包发布到npmjs公共仓库上。

7.1. 注册npm用户

官网地址:http://registry.npmjs.org

7.2 登录npm

7.2.1 第一次发包

npm adduser
username: 用户名
password:密码
email:邮箱

7.2.2 非第一次发包

npm login
username: 用户名
password:密码
email:邮箱

7.3 发包

npm publish

7.4 处理错误信息

7.4.1 E403

  1. 需要验证一下注册的邮箱
npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT http://registry.npmjs.org/xxxxxx 
- you must verify your email before publishing a new package: 
https://www.npmjs.com/email-edit
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy.
  1. 修改package.json中的 versions 版本号
npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT http://registry.npmjs.org/xxxxxxx 
- You cannot publish over the previously published versions: 0.0.2.
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy.
  1. 非官方源,
    切换到官方源: http://registry.npmjs.org
    切换之后需要重新登录。
npm ERR! 403 Forbidden - PUT http://registry.npm.taobao.com/xxxxxxx - no_perms
  1. 报名重复
npm ERR! 403 Forbidden - PUT https://registry.npmjs.org/xxxxx 
- You do not have permission to publish "xxxxx". 
Are you logged in as the correct user?
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值