原文地址:https://segmentfault.com/a/1190000006250554
github創(chuàng)建項目
https://github.com 注冊賬戶,新建項目,然后clone到本地。
終端進入到項目文件夾,執(zhí)行npm init命令,構建模塊的描述文件,系統(tǒng)會提示你輸入所需的信息,不想輸入就直接Enter跳過。這里主要的幾個配置如下:
- name就是你要發(fā)布的module名;
- version版本信息(每發(fā)布一次版本號都必須大于上一次發(fā)布的版本號);
- entry入口文件。
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
name: (react-native-dmg-pingpp)
version: (0.0.1)
license: (MIT)
npm注冊
輸入完用戶名,密碼,郵箱后沒有錯誤信息就完成了。
$ npm adduser
Username: your name
Password: your password
Email: (this IS public) your email
查詢或者登陸別的用戶命令:
$ npm whoami
$ npm login
npm module 發(fā)布
module開發(fā)完畢后,剩下的就是發(fā)布啦,進入項目根目錄,輸入命令。
$ npm publish
可能遇到的問題:
- 問題1:
npm ERR! no_perms Private mode enable, only admin can publish this module:
這里注意的是因為國內網(wǎng)絡問題,許多小伙伴把npm的鏡像代理到淘寶或者別的地方了,這里要設置回原來的鏡像。
npm config set registry=http://registry.npmjs.org
- 問題2:
npm ERR! you do not have permission to publish "your module name".
Are you logged in as the correct user?
提示沒有權限,其實就是你的module名在npm上已經被占用啦,這時候你就需要去npm搜索你的模塊名稱,如果搜索不到,就可以用,并且把package.json里的name修改過來,重新npm publish,看到如下信息就表示安裝完成了,react-native-dmg-pingpp就是我的模塊名。
+ react-native-dmg-pingpp@0.0.1
更新版本,發(fā)布
$ npm version 0.1.1
$ npm publish