npm快速发布自己的模块

创建

注意创建模块前,先去 npm 官网确认模块名是否未被占用

npm init

添加账号

$ npm adduser
Username: your name
Password: your password
Email: yourmail@gmail.com

发布

npm publish

编辑 .npmignore

如果文件夹中存在 .gitignore, 则 .npmignore 与之相同;
如果想忽略一些 .gitignore 中没有包括的东西,那么创建一个空的 .npmignore 可覆盖之.
npm 社区版本号规则采用的是 semver (语义化版本)

报错

发布时报错:no_perms Private mode enable, only admin can publish this module
因为 npm 镜像源会有延时,替换为官方源即可。

npm config set registry http://registry.npmjs.org

然后重新 adduser

镜像源

[临时] 通过 config 配置指向国内镜像源

1 # 配置指向源npm info express

2 npm config set registry http://registry.cnpmjs.org
[临时] 通过 npm 命令指定下载源

npm --registry http://registry.cnpmjs.org info express

在配置文件 ~/.npmrc 文件写入源地址

  1. //打开配置文件
  2. vim ~/.npmrc
  3. //写入配置文件
  4. registry =https://registry.npm.taobao.org

淘宝 npm 镜像

  1. //cnpm
  2. npm install -g cnpm --registry=https://registry.npm.taobao.org
  3. npm config set registry https://registry.npm.taobao.org --global
  4. npm config set disturl https://npm.taobao.org/dist --global
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值