初始化npm发布包在这里注册登录https://www.npmjs.com/,起个名字,比如http-auth-zfb,先查看mkdir是否存在http-auth-zfbcdhttp-auth-zfbnpminit-y新建入口文件index.js//index.jsmodule.exports=require('./lib/index');发布的文件放在lib文件夹下,发布的npmlogin会填写你在npmjs.com注册的用户名和密码邮箱等信息。npmloginnpmpublishupdaterelease只需要修改版本号然后如果npmpublish发布es6代码,新建src目录,将原文件(es6代码)放入src,需要babael转换"scripts":{"test":"echo\"Error:notestspecified\"&&exit1","build":"babelsrc--out-dirlib"},"devDependencies":{"babel-cli":"^6.26.0","babel-plugin-transform-runtime":"^6.23.0","babel-preset-es2015":"^6.24.1","babel-preset-stage-3":"^6.24.1"},"dependencies":{"transform-runtime":"^0.0.0"}发布前,执行npmrunbuild改造lib下的代码,更改版本号,执行npmpublisherrornpmERR!publishFailedPUT401解决过程:检查仓库是否设置为淘宝镜像库npmconfiggetregistry如果是,设置回原仓库npmconfigsetregistry=http://registry.npmjs.org登录账号(如果未登录)npm登录或添加用户npmadduser再次发布npmpublish如果发布成功,再次设置仓库地址为淘宝镜像地址npmconfigsetregistry=https://registry.npm.taobao.org/
