从无到有,发布一个你自己的npm package

第一步,npm init 就像git init一样。会让你在package.json里配置这个库的一些参数。

 ~/documents/cli/minisite-cli > npm init

Press ^C at any time to quit.
name: (minisite-cli)
version: (1.0.0)
entry point: (index.js)
test command:
license: (MIT)

一般如果你的package.json写的不错的话,就可以回车回车一直向下了

然后npm login登录你的npm账户。如果没有就去npm注册一个。

之后就可以用npm publish 来上传你的库了。

常见问题:

npm ERR! publish Failed PUT 403
npm ERR! Darwin 16.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "publish"
npm ERR! node v7.7.2
npm ERR! npm  v4.1.2
npm ERR! code E403

npm ERR! no_perms Private mode enable, only admin can publish this module: minisite-cli
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/yangzhedi/Documents/cli/minisite-cli/npm-debug.log

这可能是你把npm设置成了淘宝镜像,需要再设置回来。
npm config set registry http://registry.npmjs.org

npm ERR! Darwin 16.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "publish"
npm ERR! node v7.7.2
npm ERR! npm  v4.1.2
npm ERR! code ENEEDAUTH

npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/yangzhedi/Documents/cli/minisite-cli/npm-debug.log

需要npm adduser登录你的npm账户。

最后 npm publish 就可以上传了。

出现+ [email protected] 说明你上传成功了

你可能感兴趣的:(从无到有,发布一个你自己的npm package)