参考:
verdaccio https://github.com/verdaccio/verdaccio#readme
搭建NPM私有库 https://www.jianshu.com/p/1d0e85d14234
用npm发布包 http://www.cnblogs.com/chengxs/p/7651653.html
# 安装verdacio
npm install --global verdaccio
# 启动
verdaccio
# 更改npm配置
npm set registry http://localhost:4873/
# 如果你使用HTTPS, 添加一个适当的CA信息(“null” 的意思从系统获取CA列表)
npm set ca null
浏览 http://localhost:4873/, 这里将列出已提交的本地包(暂时还没有)
运行verdaccio时, 会建立两个默认的文件(Windows默认路径 C:\Users\Administrator.config\verdaccio): config.yaml和storge,htpasswd在添加用户后被创建
准备一个文件夹(npm_push_test), 里面包含 入口js(index.js); 最好有一个README.md文件做本地插件包的介绍, 没有也不影响;
# 初始化要封装的包
npm init
# 这里提示输入:
#- name:填写个包的名字,默认是这个文件夹的名字(npm有同名的包会报错);
#- version:包的版本,默认是1.0.0;
#- description:要封装的包的简单介绍;
#- entry point:入口文件,默认是index.js,也可以是其它名字;
#- test command:测试命令,直接回车;
#- git repository:这个是git仓库地址,如果你的包是先放到github上或者其他git仓库里,这时候你的文件夹里面会存在一个隐藏的.git目录,npm会读到这个目录作为这一项的默认值。如果没有的话,直接回车继续;
#- keyword:作为这个包的索引的关键字;
#- author:作者名或账号;
#- license:许可证, 没有就直接回车;
之后会生成一个package.json文件;
package.json
{
"name": "local_npm_push_test",
"version": "1.0.0",
"description": "npmjs package test",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"npm_push_test"
],
"author": "surliya",
"license": "ISC"
}
# 查看npm包镜像
npm config get registry
# 更改npm包镜像 (最后的最后再改回来 https://registry.npm.taobao.org)
npm config set registry http://localhost:4873/
# 注册用户(在要提交的包文件夹下注册, 这里用有用户名,密码,邮箱的输入提示)
npm adduser --registry http://localhost:4873/
# 或者 npm login
# 发布
npm publish --registry http://localhost:4873/
# 或 npm publish
# 下载
npm install local_npm_push_test
刷新 http://localhost:4873/
注:
1.发布新版本时需要改package.json文件里的版本号;
2.需要覆盖公共包时, 只需在发布时更改版本号即可;
3. npm安装更新出现 npm WARN deprecated [email protected]: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0 错误, 解决方案: 降低版本 npm install [email protected] -g