官網(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