第一步:指定registry
可以在命令行中
npm publish --registry=http://192.168.80.128:18081/repository/npm-local/
或者
在
package.json
文件下添加
publishConfig
属性
"publishConfig": {
"registry": "http://192.168.80.128:18081/repository/npm-local/"
这时,再运行
npm publish
会报401,因为没有登录
npm notice
npm notice package: test-giannuo-npm-publish@0.0.1
npm notice === Tarball Contents ===
npm notice 56B index.js
npm notice 373B package.json
npm notice === Tarball Details ===
npm notice name: test-npm-giannuo-publish
npm notice version: 0.0.4
npm notice package size: 1.4 kB
npm notice unpacked size: 4.7 kB
npm notice shasum: baed4ef13354352e5385cecc2887efd422ab09f8
npm notice integrity: sha512-y/3c1x3Hr1qHS[...]Pn+kRbt5vu0yw==
npm notice total files: 2
npm notice
npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
使用
npm login
进行登录,同样,指定目标
registry
npm login --registry=http://192.168.80.128:18081/repository/npm-local/
-
login时需要指定
registry
,且为
hosted
类型,
不能
是
public
-
registry地址最后的斜杠(
/
)
不能省略
登录之后
Logged in as giannuo on http://192.168.80.128:18081/repository/npm-local/.
再使用
npm publish
> npm publish
npm notice
npm notice package: test-npm-giannuo-publish@0.0.4
npm notice === Tarball Contents ===
npm notice 56B index.js
npm notice 373B package.json
npm notice === Tarball Details ===
npm notice name: test-npm-giannuo-publish
npm notice version: 0.0.4
npm notice package size: 390 B
npm notice unpacked size: 429 B
npm notice shasum: a258e19c465981ea02eee88975631e16e4c7c335
npm notice integrity: sha512-7LmrrU1IxfaTO[...]SiWgyhYhVqXrg==
npm notice total files: 2
npm notice
+ test-npm-giannuo-publish@0.0.4
成功
使用
npm install test-npm-giannuo-publish@0.0.4
安装验证,看看能否正常调用