你可以發(fā)布任何包含**package.json**文件的目錄,比如Nodejs模塊。
## 創(chuàng)建用戶
發(fā)布包之前,你必須創(chuàng)建一個(gè)npm用戶賬號(hào)。如果還沒有,你可以用**npm adduser**創(chuàng)建一個(gè)。如果已經(jīng)注冊(cè)了,使用**npm login**命令將賬號(hào)信息存儲(chǔ)到本地客戶端。
測(cè)試:使用**npm config ls**確認(rèn)賬號(hào)信息已經(jīng)存儲(chǔ)到您的客戶端。訪問https://npmjs.com/~ 以確保信息正確。
## 發(fā)布包
使用**npm publish**來(lái)發(fā)布程序包。
> Note that everything in the directory will be included unless it is ignored by a local **.gitignore** or **.npmignore** file as described in **npm-developers**.
注意,目錄下的所有文件都將被包含進(jìn)去,除非目錄下有**.gitignore** 或 **.npmignore**文件(詳情請(qǐng)看**npm-developers**)將其排除。
> Also make sure there isn't already a package with the same name, owned by somebody else.
同時(shí),請(qǐng)確保npm上沒有別的開發(fā)者提交的同名都包存在。
> Test: Go to **https://npmjs.com/package/<package>**. You should see the information for your new package.
測(cè)試:前往**https://npmjs.com/package/<package>**。你應(yīng)該可以看到發(fā)布的新包的信息了。
## 更新包
> When you make changes, you can update the package using npm version <update_type>, where update_type is one of the semantic versioning release types, patch, minor, or major. This command will change the version number in package.json. Note that this will also add a tag with this release number to your git repository if you have one.
當(dāng)你修改了你的包文件,你可以用`npm version <update_type>`更新它。update_type是指語(yǔ)義化版本管理的發(fā)布類型的一種:補(bǔ)丁版本(patch)、次版本(minor)或主版本(major)。此命令會(huì)更改package.json中的版本號(hào)。注意哦,如果你有此包的git倉(cāng)庫(kù),那么此命令也會(huì)向git倉(cāng)庫(kù)添加此版本的一個(gè)標(biāo)簽。
> After updating the version number, you can npm publish again.
更新版本號(hào)之后,你就可以再次 `npm publish` 了。
> Test: Go to https://npmjs.com/package/<package>. The package number should be updated.
測(cè)試:前往 **https://npmjs.com/package/<package>**,包的版本號(hào)應(yīng)該已更新了。
> The README displayed on the site will not be updated unless a new version of your package is published, so you would need to run npm version patch and npm publish to have a documentation fix displayed on the site.
站點(diǎn)下的README文件是不會(huì)更新,除非你的包的新版本發(fā)布成功。所以你需要運(yùn)行`npm version patch`和`npm publish`命令來(lái)修復(fù)站點(diǎn)下的文檔。
