npm 包发布方式(线上、线下)
线下发布
第一步,安装,开启第一个终端:
npm install -g sinopia 安装
sinopia -l 127.0.0.1:4873 打开本地地址
出现问题
callback must be a funciton received undefined
解决:
local-fs.js文件第42行修改
fs.unlink(tmp,function(){})
第二步,启动,开启第二个终端:
cd 到某个指定仓库
mkdir unit-restful-axios(包的名称)
cd unit-restful-axios
npm init
生成package.json
PS:main 为index.js
vi index.js (创建index.js)
在index.js 中复制 封装起来的方法或内容
第三步,创建新用户
npm adduser --registry http://127.0.0.1:4873
第四步,发布npm包
npm publish --registry http://127.0.0.1:4873
第五步,设置npm请求源(也可以提前设置)
npm config set registry http://127.0.0.1:4873
npm adduser --registry http://127.0.0.1:4873
npm publish --registry http://127.0.0.1:4873
sinopia -l 127.0.0.1:4873
npm config set registry http://127.0.0.1:4873
线上发布
npm 官方发布
npm config set registry https://registry.npmjs.org/
npm publish
npm login
之后
npm adduser --registry http://127.0.0.1:4873
npm publish --registry http://127.0.0.1:4873
sinopia -l 127.0.0.1:4873
npm config set registry http://127.0.0.1:4873