使用 react-native-create-library 模版创建lib
完善 package.json
具体参考 npm 官方文档 Creating a package.json file
{
"name": "npm-private-lib",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"react-native"
],
"author": "",
"license": "",
"peerDependencies": {
"react-native": "^0.41.2",
"react-native-windows": "0.41.0-rc.1"
}
}
发布 npm lib 前准备工作
1. 添加 .gitignore 和 .npmignore
2. 添加 readme.md
发布 npm lib
1. 去官网注册 npm 账号并验证通过
提交代码到远程仓库
2. 首次发布
验证是否成功, 打开npm官网登录在个人信息查看
$ npm publish
3. 非首次发布 (更新)
手动修改package.json 文件中版本号
$ npm publish
或
$ npm version <update_version>
$ npm publish
撤销发布
$ npm unpublish