npm publish 發(fā)布自己的npm包

官網(wǎng)的發(fā)布寫的比較簡單,直接就是npm pulish .但實際上直接運行這個命令很可能報錯。
正確的發(fā)布順序是:

1.初始化 package.json

npm init

2.驗證你在 npmjs.org 上的賬號

npm adduser

3.發(fā)布

npm publish .

上面三部是初次發(fā)布插件的步驟。當然,在發(fā)布前需要你先去npmjs.org上注冊一個賬號。
如果你以后修改了代碼,然后想要同步到 npm 上的話請修改 package.json 中的 version 然后再次 publish

4.安裝

npm install XXX --save

版本號規(guī)范

npm社區(qū)版本號規(guī)則采用的是semver(語義化版本),主要規(guī)則版本格式:主版本號.次版本號.修訂號,版本號遞增規(guī)則如下:

主版本號:當你做了不兼容的 API 修改,
次版本號:當你做了向下兼容的功能性新增,
修訂號:當你做了向下兼容的問題修正。

先行版本號及版本編譯信息可以加到“主版本號.次版本號.修訂號”的后面,作為延伸。

問題

問題1

no_perms Private mode enable, only admin can publish this module

那么可能是你用了國內(nèi)的鏡像地址了,只需要重新把地址注冊回npmjs即可。

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

返回淘寶鏡像

npm config set registry https://registry.npm.taobao.org

問題2

npm ERR! you do not have permission to publish "your module name". Are you logged in as the correct user?

提示沒有權(quán)限,其實就是你的module名在npm上已經(jīng)被占用啦,這時候你就去需要去https://www.npmjs.com搜索你的模塊名稱,如果搜索不到,就可以用,并且把package.json里的name修改過來,重新npm publish,看到如下信息就表示安裝完成了,rc-fullpage就是我的模塊名。

Package.json格式

{
  "name": "my_package",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "ag_dubs",
  "license": "ISC",
  "repository": {
    "type": "git",
    "url": "https://github.com/ashleygwilliams/my_package.git"
  },
  "bugs": {
    "url": "https://github.com/ashleygwilliams/my_package/issues"
  },
  "homepage": "https://github.com/ashleygwilliams/my_package"
}

name: defaults to author name unless in a git directory, in which case it will be the name of the repository
version: always 1.0.0
main: always index.js
scripts: by default creates a empty test script
keywords: empty
author: whatever you provided the CLI
license: [ISC](https://opensource.org/licenses/ISC)
repository: will pull in info from the current directory, if present
bugs: will pull in info from the current directory, if present
homepage: will pull in info from the current directory, if present

參考鏈接:
https://docs.npmjs.com/all#option-1-change-the-permission-to-npms-default-directory

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容